<a4j:命令按钮>操作仅在第二次点击时调用 [英] <a4j:commandbutton> action is only invoked on second click
问题描述
我想在单击按钮时提交数据表,但在第一次单击时不会调用该操作.这是我的代码:
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>
问题是在第二次点击时,我的
动作被调用.但它不会在第一次点击时调用.
有什么想法吗?
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?
推荐答案
这个问题被称为 JSF 规范问题 790.如果您 ajax 渲染了一些内容,而这些内容又包含 <h:form>
,那么它的视图状态将丢失,这会导致该表单中的第一个操作不会调用任何内容.在第一个动作的 ajax 响应中,表单将获得新的视图状态,因此任何后续动作都会成功.
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,您必须引入一种解决方法.你首先需要给
一个固定的 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" />
同样的故事适用于
组件.
The same story applies to <a4j:xxx>
components.
<a4j:commandButton ... render=":addToThisDepartmentPanel :yourFormId" />
另见:
- h:commandButton/h:commandLink 在第一次点击时不起作用,仅适用第二次点击
- JSF 2.0 中的通信 - 内容的 Ajax 呈现其中包含另一种形式
这篇关于<a4j:命令按钮>操作仅在第二次点击时调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!