Reputation:
I am having trouble finding an example of this in the primefaces documentation.
What I have is a very long form. For each component in the form I do have
<p:message for="abc"/>
but what I would also like to have is a single p:message at the top of the page that would say something like : "You are missing one or more required fields. Please scroll below etc etc etc"
If I add
<p:messages/>
to the top of the page ALL the fields and their required messages show up. That makes the form even more ugly than it already is.
So is there a way to detect if there is at least one required/validation error and then display something at the top of the page like my example instead of all the messages?
Upvotes: 2
Views: 1796
Reputation: 20158
You can create a phase listener to check if validation failed, and if so, add a global message. This global message can be displayed using:
<p:messages globalOnly="true"/>
See also:
Upvotes: 2