gpt4 book ai didi

jsf - 普遍跳过所需输入的验证参数

转载 作者:行者123 更新时间:2023-12-04 13:00:07 28 4
gpt4 key购买 nike

如何制作一些可以跳过 web 所需验证的按钮(但我仍然想处理所有数据,所以立即等等不可能是真的)。

重要的是它必须是通用的。目前,我在每个必需的字段条件中都使用了一些请求参数。下面的代码示例

<p:inputText value="#{cc.attrs.data.exampleData1}" 
required="#{param['onlySave'] == null}"/>
<p:inputText value="#{cc.attrs.data.exampleData2}"
required="#{param['onlySave'] == null}"/>
<p:inputText value="#{cc.attrs.data.exampleData3}"
required="#{param['onlySave'] == null}"/>

<p:commandButton value="Zapisz zmiany"
action="#{cc.attrs.controller.save()}"
update="@form">
<f:param name="onlySave" value="true"/>
</p:commandButton>

这个解决方案很好,因为我可以在每个页面中将此参数添加到按钮并跳过验证,但是当我的保存按钮没有进行任何重定向时,如果保存方法中的某些 Java 验证失败,我只是添加了一些没有重定向的消息然后我从输入中丢失了所有必需的样式。

有没有可能设置 onlySave参数为 null在验证失败时的保存方法中或者一些更好的解决方案?

编辑: Balus 的回答很好,但使用 bean 验证,例如:
@Pattern(regexp = "^([^0-9]*)$", message = "only non numbers")
String field;

它处理该字段之外的所有数据。最好的方法是仅忽略必需的字段属性,而不是验证等。

编辑 2:
<tr>
<td class="label">
<p:outputLabel id="label" for="#{cc.attrs.componentId}" value="#{cc.attrs.label}"/>
</td>
<td class="value">
<cc:insertChildren/> --here component with componentId
</td>
</tr>
<tr class="errorMessage">
<td class="label"/>
<td class="value">
<p:message id="error" for="#{cc.attrs.componentId}" />
</td>
</tr>

最佳答案

请参阅以下必填字段的修改代码。您可以将 #{empty param.onlySave} 用于要跳过验证的字段并根据您的要求。

<p:inputText value="#{cc.attrs.data.exampleData1}" 
required="#{not empty param.onlySave}"/>
<p:inputText value="#{cc.attrs.data.exampleData2}"
required="#{not empty param.onlySave}"/>
<p:inputText value="#{cc.attrs.data.exampleData3}"
required="#{not empty param.onlySave}"/>

<p:commandButton value="Zapisz zmiany"
action="#{cc.attrs.controller.save()}"
update="@form">
<f:param name="onlySave" value="true"/>
</p:commandButton>

关于jsf - 普遍跳过所需输入的验证参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31292487/

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