许多问题与这个问题非常相似,但我找不到解决方案。
以下代码没有给出错误,但行为不符合预期。 它显示三列:
第一列是一个复选框,用于激活第二列的可编辑字段
第3列是行删除方法
第四列只是一个转到下一页的按钮
<h:column> <h:panelGroup id="editCol"> <f:facet name="header"> <h:outputText value="Edit" style="font-weight: bold"> </h:outputText> </f:facet> <h:selectBooleanCheckbox value="#{m.editable}" onclick="submit()"> <f:ajax execute="editCol :formId:dataId:authorCol" render="editCol :formId:dataId:authorCol" /> </h:selectBooleanCheckbox> </h:panelGroup> </h:column> <h:column> <h:panelGroup id="authorCol"> <f:facet name="header"> <h:outputText value="Label" style="font-weight: bold"> </h:outputText> </f:facet> <h:inputText value="#{m.author2displayed}" rendered="#{m.editable}" size="10"/> <h:outputText value="#{m.author2displayed}" rendered="#{not m.editable}"/> <h:commandButton value="save edits" rendered="#{m.editable}" onclick="submit()" action ="#{finalCheckBean.saveedits()}"> <f:ajax execute="authorCol" render="authorCol" /> </h:commandButton> </h:panelGroup> </h:column> <h:column> <h:panelGroup id="deleteCol"> <f:facet name="header"> <h:outputText value="delete row(s)" style="font-weight: bold"> </h:outputText> </f:facet> <h:selectBooleanCheckbox value="#{m.deleted}" onclick="submit()"/> <h:commandButton value="delete row(s)?" rendered="#{m.deleted}" onclick="submit()" action ="#{finalCheckBean.deleteRow()}"/> </h:panelGroup> </h:column> <h:column> <f:facet name="header"> <h:commandButton value="save changes" action="#{finalCheckBean.moveon}"/> </f:facet> </h:column> </h:dataTable>
当我勾选
selectBooleanCheckbox
时在第一列中,该框被勾选但没有任何反应,而实际上应该切换第二列中组件的显示。有趣的是,当我然后点击
selectBooleanCheckbox
在不使用 ajax 的第三列中,第二列将重新渲染,我可以看到步骤 1 中勾选操作的效果。
我怎样才能制作我的selectBooleanCheckbox
第一列工作正常吗?
最佳答案
<h:selectBooleanCheckbox ... onclick="submit()">
<f:ajax ... />
</h:selectBooleanCheckbox>
您的具体问题是由 onclick="submit()"
引起的在 ajax 复选框上。去掉它。正在触发 form.submit()
这与 <f:ajax>
完全冲突.
您还在其他无 ajax 复选框上使用它,这可能没问题,但您也在“删除行?”上使用它。完全没有必要的命令按钮。它默认已经触发表单提交。
关于jsf - ajax 调用后组件不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12568445/