Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call order of h:commandLink action and f:ajax listener

Here is my markup:

<h:commandLink value="#{partial}" action="#{hello.setCurrentPartial(partial)}">
    <f:ajax render="include" listener="#{hello.renderFragments}"/>
</h:commandLink>

I tried to run this page in Mojarra-2.2.8(wildfly 8.2.0.Final built-in) and MyFaces-2.2.7(installed as guided here). Surprisingly, when the link is clicked, mojarra calls hello.renderFragments first and then hello.setCurrentPartial, but MyFaces takes the opposite order, i.e., hello.setCurrentPartial is called first.

So my question is whether there is a definition of the call order of action and ajax listener in JSF Spec. Which implementation is correct if the order is defined?

like image 759
xiefei Avatar asked Mar 06 '15 14:03

xiefei


People also ask

What is Ajax listener?

This attribute is used to call Java method by using an Ajax request. It is an attribute of <a:ajax> component. Here, we are creating an example that calls a method from ManagedBean. It includes the following files and code.

Which method collects the data provided by the f Ajax tag?

request() method of the JavaScript resource library collects the data provided by the f:ajax tag and posts the request to the JavaServer Faces lifecycle.

What is H commandLink?

h. Tag commandLink. Render an HTML "a" anchor element that acts like a form submit button when clicked.

What is Ajax in Primefaces?

Ajax Attributes It is used to process in partial request. Immediate. false. boolean. It returns a boolean value that determines the phaseId, when true actions are processed at apply_request_values, when false at invoke_application phase.


1 Answers

As per the EG discussion, there's agreement on Mojarra behavior being correct as it's in line with how actionListener/action work. The MyFaces guy has created an issue on it and it's expected that this will be fixed for next MyFaces release. And, the JSF spec should be more explicit in this, this will be worked on.

In the meanwhile, if you want to have the same behavior in both Mojarra and MyFaces as to the method invocation order, move the <f:ajax listener> to <h:commandLink actionListener>.

<h:commandLink value="#{partial}" actionListener="#{hello.renderFragments}" action="#{hello.setCurrentPartial(partial)}">
    <f:ajax render="include" />
</h:commandLink>

See also:

  • Differences between action and actionListener
like image 145
BalusC Avatar answered Sep 23 '22 13:09

BalusC