h:messages does not display messages when p:commandButton is pressed

You’re sending an ajax request with PrimeFaces <p:commandButton>. Ajax requests have by default no form of feedback (unless PrimeFaces’ autoUpdate="true" is been used somewhere). You should be explicitly specifying parts of the view which you’d like to update on ajax response.

One way is specifying the update attribute on <p:commandButton> to point to the client ID of the <h:messages> component.

<h:messages id="messages" ... />
<h:form>         
    <p:commandButton ... update=":messages" />
</h:form>

Another way is to replace it by PrimeFaces <p:messages> which has an autoUpdate attribute for the purpose of automatic update on ajax response.

<p:messages ... autoUpdate="true" />
<h:form>         
    <p:commandButton ... />
</h:form>

A completely different alternative is to turn off ajax by adding ajax="false" attribute to the button, this way a synchronous postback will be performed which effectively results in a full page update, exactly like as how the standard JSF <h:commandButton> behaves when used without <f:ajax>.

<h:messages ... />
<h:form>         
    <p:commandButton ... ajax="false" />
</h:form>

See also:

Leave a Comment