Moin!
I have a situation where I try to display an error message using p:message for an Exception that is raised in a getter. But this results into the message "WARNUNG: There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered.".
I do the following to attach the Message to FacesContext:
FacesContext.getCurrentInstance().addMessage(cliendId, getFacesMessage(severity, msgKey, args));
I think the message cannot be rendered, because, creating a message in a getter happens in a phase where it is to late to render it…
Is there a way to create a message in a getter instead of in an action?
Maybe it is possible to reset the rendering phase?
Doing the business job in a getter method is the wrong approach. In JSF managed beans, a getter should not do anything else than just returning the data or at least to do some precalculations on the already-available properties. You should not assign property values inside a getter method, or it must be for lazy loading.
The getter is invoked during rendering of the view. In your particular case, the getter is aparently invoked after the
<p:messages>is been rendered and thus it never gets the chance to show the faces message which is been added later on.Move the business job to the (post)constructor or an (action)listener method of the backing bean instead.
E.g. in postconstruct method:
You could of course also move the
<p:messages>to the very bottom of the page (and if necessary reposition it using CSS), but that’s more a workaround than a solution.See also: