Lately I had problems with displaying a FacesMessage. I suspected that it was due to creating it inside a property get-method. As a proof I created a simple demo application.
1 2 3 4 5 6 7 8 9 10 11
The class above contains an action method that creates FacesMessage instance and adds it to the FacesContext through some helper class. A get-method (for pseudo property facesMessage) calls this action method.
A JSP view is using these methods to show the effect described.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
The JSP contains a button that triggers the action method, every time it is clicked a faces message is shown. It also shows the property facesMessage which is bound to the method getFacesMessage.
So one would think that every time the view is show, it also produces a faces message on top of the form - it doesn’t. Here is why:
As a result the messages have alread been rendered when the new faces message is created. You only have 2 choices to remedy. Either you move the messages tag to the very bottom of the form or you make sure that any method that is possibly creating a faces message is invoked in an earlier phase than the RENDER_RESPONSE phase!