< a4j:commandbutton>仅在第二次单击时调用操作 [英] <a4j:commandbutton> action is only invoked on second click

查看:89
本文介绍了< a4j:commandbutton>仅在第二次单击时调用操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击按钮时提交数据表,但是第一次单击时不会调用该操作.这是我的代码:

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:

<h:panelGrid id="addToThisDepartmentPanel">
    <h:outputText value="#{messageDataBean.message}" rendered="#{messageDataBean.isSuccess eq false}" style="color:red" id="addToThisDepartmentMessage"/>
    <h:form>
        <h:dataTable value="#{systemResultViewUtil.systemUserDetailDataBeansList}" var="departmentdetail" id="addToThisDepartmentDataTable" rendered="#{systemResultViewUtil.systemUserDetailDataBeansList.size() gt 0}">
            <h:column>
               <f:facet name="header">
                   Name
               </f:facet>
               <h:outputText value="#{departmentdetail.name}" style="text-align: left;padding-right: 120px" />
            </h:column>
            <h:column>
                <f:facet name="header">
                    Current Department
                </f:facet>
                <h:outputText value="#{departmentdetail.depName}" style="text-align: left;padding-right: 120px" />
            </h:column>
            <h:column>
                <f:facet name="header">
                    Add To This
                </f:facet>
                <h:selectBooleanCheckbox value="#{departmentdetail.cheked}" style="text-align: left;padding-right: 120px"/>
            </h:column>
         </h:dataTable>

         <a4j:commandButton oncomplete="if(#{messageDataBean.isSuccess eq true}){ closeAddToThisDepartmentDialog()}" value="Add TO This Department" action="#{departmentServiceBean.addEmployeeToThisDepartment}" id="addToThisDepartmentButton"
                                                       render=":addToThisDepartmentMessage :message" execute=":addToThisDepartmentDataTable" />
     </h:form>
</h:panelGrid>

问题在于第二次单击时,调用了我的<a4j:commandButton>动作.但第一次点击时不会调用它.
有什么想法吗?

The problem is that on the second click my <a4j:commandButton> action is called. But it is not called on the first click.
Any ideas?

推荐答案

此问题称为

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.

此问题计划在即将发布的JSF 2.2中修复.但是现在使用JSF 2.0/2.1,您必须引入一种解决方法.在下面的示例中,您首先需要给<h:form>一个固定的ID,该ID为yourFormId:

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">
        ...

然后,您还需要在render属性中引用它:

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

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

同一故事适用于<a4j:xxx>组件.

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

另请参见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆