I am using JSF 2.2 (Myfaces 2.2.9).
I want to iterate over messages in JSF to display the errors, and I have some trouble with the ui:repeat element.
My .xhtml page :
message size = #{facesContext.messageList.size()}
<br />
<ui:repeat var="msg" value="#{facesContext.messageList}">
#{msg.detail}
</ui:repeat>
When my form is submitted, it calls a function of my backing bean.
In that function, I add an "INFO" global message and I get it when my .xhtml page is displayed :
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "info message", "info message"));
Then it displays :
message size = 1
info message
But if I change the severity to SEVERITY_ERROR :
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "info message", "info message"));
then the view does not display any message, even though the size is not empty:
message size = 1
Same if I just add the error message after the info message :
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "info message", "info message"));
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "error message", "error message"));
message size = 2
It seems adding a message of severity different from INFO is screwing things. Any help would be greatly appreciated, this is driving me crazy...
I checked many answers talking about the life cycle (BalusC answers), and what I understood is that ui:repeat is executed as render time. So it should work.