Home » Java » Primefaces – Do not display message for required fields, just hightlight border

Primefaces – Do not display message for required fields, just hightlight border

Posted by: admin December 28, 2021 Leave a comment

Questions:

I have a Primefaces 3-field form and a <p:messages> tag to show some server-side validation messages. But I don’t want to display the client-side messages related to the required="true" option, just highlight the input field with red.

Is there a way to do it with Primefaces?

Answers:

You can set <p:messages globalOnly="true"/>, this will just show global messages, which are not attached to any particular field. Also you can user Primefaces’ <p:outputLabel/> for label of input elements, it will add error css to input elements.

You should also update form when you do submit. For example if you do that with command button add update="form_id"

###

I did it like this –> rendered=”#{not facesContext.validationFailed}”

 <p:messages
    rendered="#{not facesContext.validationFailed}"
    id="msg"
    showDetail="true"
    autoUpdate="false"
    closable="true" />