action is only invoked on second click

前端 未结 1 741
醉话见心
醉话见心 2020-12-01 11:34

I want to submit a data table on a button click, but that action is not called on the first click. Here is my code:



        
相关标签:
1条回答
  • 2020-12-01 12:08

    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:

    • h:commandButton/h:commandLink does not work on first click, works only on second click
    • Communication in JSF 2.0 - Ajax rendering of content which contains another form
    0 讨论(0)
提交回复
热议问题