Quite a while ago I had posted about generating a FacesMessage within a method that is called during the RENDER_RESPONSE phase. Today I had to find a way to display those at the very top of a page and none of the message should get lost.

So I came up with trying that with jQuery (in my case it is already included in Rich-Faces that I was using here). The idea is to actually render all FacesMessage objects at the very bottom of the page and once the page has finished loading move its DOM tree up where it was supposed to be displayed.

1
2
3
4
5
6
7
8
9
<div id="messagesTarget"</div>
...
...
<rich:panel id="messagesSource" rendered="#{! empty facesContext.maximumSeverity}">
  <rich:messages showDetail="true" showSummary="true" errorClass="errorSeverity" warnClass="warningSeverity"
      infoClass="infoSeverity" />
</rich:panel>

<rich:jQuery selector="$('messagesTarget')" query="append($('messagesSource'))" timing="onload" />

Comments