The h:messages
is for so-called global messages which are unrelated to a specific component and therefore the for
attribute is not allowed here.
The h:message
is for messages related to a specific component, therefore the for
attribute is required, this means you need a component to bind to.
To reach your goal you can use two h:message
elements bound to some component (e.g. an empty h:grapicImage
) in the following way:
<h:graphicImage id="someID" />
<h:message for="someID" id="container-messages" infoClass="info-message"
warnClass="warn-message" errorClass="error-message"/>
<div>
stuff
</div>
<h:message for="someID" id="aside-messages" infoClass="info-message"
warnClass="warn-message" errorClass="error-message" />
Adding the messages in the way you already described:
facesContext.addMessage("container-messages", new
FacesMessage(FacesMessage.SEVERITY_INFO, "message1", null));
facesContext.addMessage("aside-messages", new
FacesMessage(FacesMessage.SEVERITY_INFO, "message2", null));
See also: