Creating FacesMessage in action method outside JSF conversion/validation mechanism?

You can use FacesContext#addMessage() to add a FacesMessage to the context programmatically.

FacesContext facesContext = FacesContext.getCurrentInstance();
FacesMessage facesMessage = new FacesMessage("This is a message");
facesContext.addMessage(null, facesMessage);

When you set the client ID argument with null, it will become a global message. You can display and filter them using <h:messages />

<h:messages globalOnly="true" />

The globalOnly="true" will display only messages with a null client ID.

You can however also specify a specific client ID.

facesContext.addMessage("formid:inputid", facesMessage);

This one will then end up in

<h:form id="formid">
    <h:inputText id="inputid" />
    <h:message for="inputid" />

Leave a Comment