如何在需要时跳过 JSF 2 中某些字段的验证
我有两个 p:dialog。每个字段都包含一些被标记为必填的输入字段。一次只显示一个对话框,但当我提交任何对话框时,JSF 还会验证未显示的对话框的输入字段。对于未显示的对话框,跳过 JSF 2 中的验证的最佳方法是什么。一种方法可能是我设置 required="condation"。但不知道这种情况可能是什么以及它是否会起作用。
每个对话框最初都是隐藏的。每个按钮都有自己的显示按钮。当其中一个处于活动状态并且我单击“保存”按钮时,即使必填字段具有值,也会出现验证错误。验证错误来自非活动对话框面板。也许它能让我知道我正在尝试做什么。
更新
<p:dialog header="Edit Group" widgetVar="dialog_groupEdit" resizable="false"
width="300" showEffect="bounce" hideEffect="explode" modal="true" position="center">
<h:panelGrid id="panel_groupEdit" columns="2">
<h:outputText value="Group Name: "/>
<h:inputText id="input_gnameEdit" size="26" value="#{groupBean.selectionGroup.gname}" required="true" requiredMessage="Edit Group: Name is required."/>
<h:outputText value="Description:"/>
<h:inputTextarea rows="6" cols="23" value="#{groupBean.selectionGroup.description}"/>
<div></div>
<p:commandButton value="Save" action="#{groupBean.saveGroupChanges}" oncomplete="#{args.validationFailed ? '':'dialog_groupEdit.hide()'}"
update="panel_groups panel_groupEdit" style="float:right;"/>
<div></div>
<p:message for="input_gnameEdit"/>
</h:panelGrid>
</p:dialog>
<p:dialog header="New Group" widgetVar="dialog_groupCreate" resizable="false"
width="300" showEffect="bounce" hideEffect="explode" modal="true" position="center">
<h:panelGrid id="panel_groupCreate" columns="2">
<h:outputText value="Group Name: "/>
<h:inputText id="input_gnameCreate" size="26" value="#{groupBean.createGroup.gname}" required="true" requiredMessage="New Group: Name is reqired."/>
<h:outputText value="Description:"/>
<h:inputTextarea rows="6" cols="23" value="#{groupBean.createGroup.description}"/>
<div></div>
<p:commandButton value="Save" actionListener="#{groupBean.saveGroupCreate}" oncomplete="#{empty groupBean.createGroup.gname ? ' ':'dialog_groupCreate.hide()'}"
update="panel_groupCreate panel_groups" style="float:right;"/>
<div></div>
<p:message for="input_gnameCreate"/>
</h:panelGrid>
</p:dialog>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这会很笨拙。只需将每个单独的表单放入其自己单独的
组件中,或使用
的process
属性即可> 确定您想要处理的区域。拥有“上帝”形态无论如何都是一种糟糕的做法。
另请参阅:
This is going to be clumsy. Just put each individual form in its own separate
<h:form>
component, or use theprocess
attribute of the<p:commandButton>
to identify the region you'd like to process.Having a "God" form is in any way a poor practice.
See also:
当您使用 时,PF 论坛上建议的一些良好做法是 -
例如
When you are using
<p:dialog
some of the good practices as advised on the PF forum are -<p:dialog
inside any other component. Place it somewhere so that it falls right under the<h:body
.<p:dialog
it's own form. But, don't place the dialog inside the form, place the form inside the dialog. It's not good to update the dialog itself, only it's content. (I think this should solve your issue also.)e.g.