gpt4 book ai didi

validation - 如何在需要时跳过 JSF 2 中某些字段的验证

转载 作者:行者123 更新时间:2023-12-03 13:34:11 24 4
gpt4 key购买 nike

我有两个 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>

最佳答案

One approach could be that I set the required="condation".

这会很笨拙。只需将每个单独的表格放在自己单独的 <h:form> 中组件,或使用 process <p:commandButton> 的属性确定您要处理的区域。

<p:commandButton process="panel_groupEdit" ... />

...

<p:commandButton process="panel_groupCreate" ... />

拥有“上帝”形式无论如何都是一种糟糕的做法。

另见:

关于validation - 如何在需要时跳过 JSF 2 中某些字段的验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7986048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com