The first argument to FacesContext#addMessage() should be the client identifier, not the component identifier. The client identifier is what you see as the identifier of the HTML element in the generated HTML output (as you can see by right-clicking and View Source in the browser). For input components and JSF commands in a form, the form identifier prefix is โโusually used.
So for the next link
<h:form id="formId"> ... <h:commandLink id="linkId" ... /> <h:message for="linkId" /> </h:form>
You should add a message as follows:
FacesContext.getCurrentInstance().addMessage("formId:linkId", message);
However, a more canonical approach for displaying global messages, as you would from an action method, simply uses <h:messages globalOnly="true" /> , which you can fill with messages with a client identifier of null .
So,
<h:form id="formId"> ... <h:commandLink id="linkId" ... /> <h:messages globalOnly="true" /> </h:form>
with
FacesContext.getCurrentInstance().addMessage(null, message);
See also:
source share