How to call action method and then redirect to page sending query parameters ?

Splash Forums PrettyFaces Users How to call action method and then redirect to page sending query parameters ?

This topic contains 7 replies, has 3 voices, and was last updated by  Christian Kaltepoth 4 years, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #19146

    jllado
    Participant

    Hello!

    I must execute method before leaving the page. So I use h:commandLink.

    The first case is with f:ajax:

    <h:commandLink action="pretty:forum" styleClass="forumNameLink" value="#{forum.name}">
    <f:param value="#{forumsBacking.forumName}" />
    <f:ajax event="click" listener="#{forumsBacking.resetPagingInfo}" />
    </h:commandLink>

    It calls method but does not redirect me to page specified in ‘action’ attribute.

    The second case:

    <br />
    <h:commandLink action="#{forumsBacking.resetPagingInfo}" styleClass="forumNameLink" value="#{forum.name}">
    <f:param value="#{forumsBacking.forumName}" />
    </h:commandLink>

    The action method is :

    public String resetPagingInfo() {
    System.out.println("Is this method invoked after click");
    pagingInfo = new PagingInfo();
    return "pretty:forum";
    }

    The action method is called and this is logged:

    INFO: Is this method invoked after click

    WARNING: PrettyFaces: Exception occurred while building URL for MappingId < forum >, Required value  < #{forumId} > was null
    com.ocpsoft.pretty.PrettyException: PrettyFaces: Exception occurred while building URL for MappingId < forum >, Required value < #{forumId} > was null
    at com.ocpsoft.pretty.faces.beans.ExtractedValuesURLBuilder.buildURL(ExtractedValuesURLBuilder.java:69)
    at com.ocpsoft.pretty.faces.application.PrettyRedirector.redirect(PrettyRedirector.java:72)
    at com.ocpsoft.pretty.faces.application.PrettyNavigationHandler.handleNavigation(PrettyNavigationHandler.java:57)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:130)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIData.broadcast(UIData.java:1093)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:807)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505)
    at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476)
    at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305)
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:137)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:161)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

    Finally I use <pretty:link> instead of h:commandLink and I am redirected to needed forum. Everything is correct

    except action method can not be called even using <f:ajax> it is not called!

    How to call action method and then redirect to page sending query parameters ?

    Finally the ‘forum’ mapping:

    <url-mapping id="forums">
    <pattern value="/forums" />
    <view-id value="/forums.xhtml" />
    </url-mapping>
    <url-mapping parentId="forums" id="forum">
    <pattern value="/#{forumId}">
    </pattern>
    <view-id value="/forum.xhtml" />
    </url-mapping>

    Thank you!

    #23298

    Could you please post your mapping? Thanks. :)

    #23299

    jllado
    Participant

    My mapping is at the bottom of my first post.

    According to this mapping I should provide #{forumId} as a parameter. For this I have

    <f:param value=”#{forumsBacking.forumName}” />

    in h:commandLink.

    #23300

    Sorry, I missed it in your post. Now it got it.

    Could you try the second approach (without ajax) and do this instead?

    public String resetPagingInfo() {
    System.out.println("Is this method invoked after click");
    pagingInfo = new PagingInfo();
    return "/forum.xhtml?faces-redirect=true&forumId="+targetForumId;
    }

    I think this is simpler in your case. If you return something like pretty:forum from your action method, PrettyFaces requires the value of the forumId to correctly build the URL to redirect to. For this it tries to extract the current value from the corresponding property, which doesn’t seem to work in your case.

    If you are using the code I showed above, it should work. :)

    #23301
    #23302

    jllado
    Participant

    You are great!

    It works regardless that I have rewrite rule for /forum.xhtml

    <rewrite match=”/forum.xhtml” substitute=”/resource_not_found” redirect=”301″ />

    Nobody can access forum.xhtml without going through ‘forum’ mapping which ensures that name of forum (forumId) is provided.

    #23303

    Yes, Christian is great :)

    #23304

    ;)

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

Comments are closed.