2

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?

1 Answers1

1

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:

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • Thank you for the answer Jasper however due to limitations out of my control I cannot utilize Omnifaces. Would there be another alternative using strictly only JSF perhaps? –  Nov 01 '17 at 16:23
  • @TarPatel I've added a plain vanilla JSF option to the answer in the linked question. – Jasper de Vries Nov 01 '17 at 16:42