JSF f: ajax listener vs commandButton action

I'm curious what is the difference between these two ways of making ajax calls:

<h:commandButton value="Submit" action="#{bean.action}"> <f:ajax execute="@form" render="component"/> </h:commandButton> 

and

 <h:commandButton value="Submit"> <f:ajax listener="#{bean.action}" execute="@form" render="component"/> </h:commandButton> 

It seems that people use the first method more often, but the second seems to work very well ...

+7
source share
1 answer

The first method allows navigation by returning a String result, and the second does not. The second method will not cause anything if the client is disconnected by JS, and the first method gracefully degrades . In fact, the first method is used more often.

The second method is the only way in components that do not have an action attribute, for example, <h:selectOneMenu> , etc.

+13
source

All Articles