gpt4 book ai didi

jsf - 验证失败时添加一般消息

转载 作者:行者123 更新时间:2023-12-04 14:26:49 25 4
gpt4 key购买 nike

我有一个包含各种字段的表单,对于每个字段,当验证失败时,我都有一个验证器和 p:message 附加。
仅当验证失败(我不想使用咆哮)时,我才需要在页面\表单顶部添加一 strip 有自定义文本的消息(例如:“请修复表单中的所有问题”)。

如何设置自定义消息以及如何触发它显示(它未附加到特定字段)。

我正在使用 JSF 2 和 primeface 3.4。

最佳答案

你可以放置

<h:panelGroup id="my_custom_error_msg">
<h:outputText value="Please fix all problem in form"
rendered="#{facesContext.validationFailed}"/>
</h:panelGroup>

并在表单提交时呈现它,例如:
<h:commandButton value="Submit">
<f:ajax render="@form my_custom_error_msg" execute="@form"/>
</h:commandButton>

如果您还有一些自制的验证和消息从您的 bean 发送到您的页面,您可以扩展 rendered条件成
rendered="#{facesContext.validationFailed or not empty facesContext.messageList}"

关于jsf - 验证失败时添加一般消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21376751/

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