4
votes

I have a form with all kind of fields and for each field I have a validator and p:message attached when validation failed. I need to add a message at top of the page\form with custom text(something like: "please fix all problem in form") only if I have a validation failure(I don't want to use growl).

how do I set the custom message and how do I trigger it to show(it is not attached to a specific field).

I'm using JSF 2 and primeface 3.4.

1

1 Answers

2
votes

You can place

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

And render it upon form submit, for example:

<h:commandButton value="Submit">
    <f:ajax render="@form my_custom_error_msg" execute="@form"/>
</h:commandButton>

If you also have some homemade validation and messages sent from your bean to your page you can extend the rendered condition into

rendered="#{facesContext.validationFailed or not empty facesContext.messageList}"