user590586
user590586

Reputation: 3050

jsf richfaces a4j:jsFunction forward outcome

Is it possible to create a4j:jsFunction that will call a method inside my managed bean and from there to perform forward to another jsf page ?

Thank's In Advance.

Upvotes: 0

Views: 1139

Answers (2)

fonkap
fonkap

Reputation: 2509

Well, it is not really a forward but you can do a redirect:

Just be sure that your corresponding navigation-case in faces-config file has the corresponding tag:

<redirect />

Then after the ajax call the browser will be redirected to the specified page.

This has the disadvantage in respect to Luiggi's response that makes two server calls, the ajax one and then the redirection.

As advantage, it makes cleaner code.

Upvotes: 0

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

No, it's not possible because the <a4j:jsFunction> will create a javascript method available in the HTML that communicates with the server via Ajax. Instead, you could do something ugly like this:

<h:form id="myForm">
    <a4j:jsFunction name="myJSFunction" action="#{myBean.jsLogic}"
        oncomplete="document.getElementById('myForm:btnForward').click();" />
    <a4j:commandButton id="btnForward" style="display: none;"
        action="#{myBean.doForward}" />
</h:form>

In this case at the end of your js function, you will call the method of a <a4j:commandButton> (also <a4j:commandLink> or any other h component) that could do the navigation.

Upvotes: 1

Related Questions