验证失败时添加常规消息

时间:2014-01-27 09:07:38

标签: jsf jsf-2 primefaces

我有一个包含所有类型字段的表单,对于每个字段,我在验证失败时附加了验证器和p:消息。 我需要在页面\ form的顶部添加一条消息,其中包含自定义文本(例如:“请修复表单中的所有问题”),只有在我验证失败时(我不想使用growl)。

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

我正在使用JSF 2和primeface 3.4。

1 个答案:

答案 0 :(得分:2)

你可以放置

<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}"