JSF f:ajax listener vs commandButton action

ぐ巨炮叔叔 提交于 2019-12-17 18:27:45

问题


I'm curious what is the difference between these two ways of executing 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 appears that people use the first way more often, but the second seems to work just fine as well...


回答1:


The first way allows for navigation by returning a String outcome and the second not. The second way won't invoke anything if the client has JS disabled, while the first way gracefully degrades. Indeed, the first way is used more often.

The second way is the only way in components which doesn't have an action attribute, such as <h:selectOneMenu> and so on.



来源:https://stackoverflow.com/questions/12222687/jsf-fajax-listener-vs-commandbutton-action

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!