I have a JSF 2.1 + PrimeFaces 3.3 page:
How do I show them in the page?
You need to specify a valid client ID. The client ID is not the same as component ID. The client ID is whatever you see in the JSF-generated HTML output. Also, the client ID should be the one of the input component, not of the message component.
So, given a
the input component has the client ID particular:name1
(rightclick page in browser and do View Source to see it yourself). So, the message should be attached on exactly this client ID.
context.addMessage("particular:name1", message);
And, a second question, if I submit the form with three empty input fields, it shows "required input error message" in each
associated with the
. How do I show them in the
?
The
is not the valid component for that, you should use
.
The globalOnly="true"
attribute means that only messages with a null
client ID will be shown. So, you should just add exactly such a message.
context.addMessage(null, message);
Unrelated to the concrete problem, the non-global messages ("Invalid name") which you're trying to add there should actually be done by a fullworthy validator. See also How to perform validation in JSF, how to create a custom validator in JSF for a concrete example.