【发布时间】:2020-01-03 03:02:17
【问题描述】:
我有一个带有树形按钮的表单。其中一个是返回上一页的“取消”按钮。
问题是存在任何验证问题,例如未提交必填字段,当我返回表单时未重置字段的样式。
这是xhtml的简化结构:
<panel id="horizontal">
<form id="filterVipLoungeForm">
</form>
<form id="frmAddPax">
<form id="frmAccessType">
</form>
</form>
<panelGrid>
<commandButton value="agregar" />
<commandButton value="limpiar" />
<commandButton value="cancelar" />
</panelGrid>
</panel>
调用添加乘客表单的按钮代码:
<p:commandButton
value="#{label['manageVipLoungeEntrance.button.addPassenger']}"
action="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 1)}"
actionListener="#{manageVipLoungeEntranceExtMB.hideMainForm}"
update=":filterVipLoungeForm :horizontal">
</p:commandButton>
取消按钮的代码:
<p:commandButton
value="#{label['manageVipLoungeEntrance.button.cancel']}"
onclick="showLocalDate()"
action="#{manageVipLoungeEntranceExtMB.setRenderStatus(0, 1)}"
actionListener="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 0)}"
update=":filterVipLoungeForm :horizontal">
</p:commandButton>
这会从支持 bean 调用 setRenderStatus 中调用一个方法,该方法设置表单和要在渲染属性中评估的渲染状态。
在这个过程中取消按钮的表单的渲染状态设置为false,前一个表单的渲染状态设置为true。
hideMainForm方法调用两次setRenderStatus方法,设置主窗体渲染状态为false,添加乘客渲染状态为true。
问题存在任何验证错误,如果我返回上一页并返回表单,我仍然会收到验证错误。
[编辑]
对不起,我忘记添加本文中包含的两种形式的渲染评估代码:
表单“frmAddPax”的渲染状态验证
<h:form id="frmAddPax" rendered="#{manageMB.renderStatus.isRenderFormAddPax()}">
表单“filterVipLoungeForm”的渲染状态验证
<h:form id="filterVipLoungeForm" style="width:95% !important;"
rendered="#{manageMB.renderStatus.isRenderFormMain()}"
onkeypress="return event.keyCode != 13">
我尝试过使用<p:resetInput>,但它不起作用,我期待带有 id frmAddPax 的表单重置他的状态,但它不起作用:
<p:commandButton
value="#{label['manageVipLoungeEntrance.button.cancel']}"
onclick="showLocalDate()"
action="#{manageVipLoungeEntranceExtMB.setRenderStatus(0, 1)}"
actionListener="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 0)}"
update=":filterVipLoungeForm :horizontal">
<p:resetInput target=":frmAddPax" />
</p:commandButton>
【问题讨论】:
-
在这种情况下,问题不在于验证样式为红色,即使 textInputs 上有数据。这个问题是关于当有任何带有红色样式的字段时,即使我返回上一页也会保持这种状态。
-
嵌套表单不好,stackoverflow.com/questions/21179403/… 有帮助吗?
-
对于这种情况,您想使用 Resetnput:primefaces.org/showcase/ui/misc/resetInput.xhtml
-
@Mellonware 我之前尝试过
没有运气,但我没有意识到有一个 我只是使用了那个并且可以工作!!。谢谢!!!
标签: primefaces jsf-2