<a4j:commandbutton> action is only invoked on second click

怎甘沉沦 提交于 2019-11-27 08:06:47
BalusC

This problem is known as JSF spec issue 790. If you ajax-render some content which in turn contains a <h:form>, then its view state will get lost, which causes that the 1st action inside that form won't invoke anything. On the ajax response of the first action, the form will get new view state and thus any subsequent actions will succeed.

This is scheduled to be fixed for the upcoming JSF 2.2. But right now with JSF 2.0/2.1 you have to introduce a workaround. You first need to give the <h:form> a fixed ID which is yourFormId in the below example:

<h:panelGrid id="addToThisDepartmentPanel">
    ...
    <h:form id="yourFormId">
        ...

Then you need to reference it in the render attribute as well:

<f:ajax ... render=":addToThisDepartmentPanel :yourFormId" />

The same story applies to <a4j:xxx> components.

<a4j:commandButton ... render=":addToThisDepartmentPanel :yourFormId" />

See also:

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