1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Theflex
  • 61
  • 4
  • Why are you not using ``? – unwichtich Mar 11 '16 at 14:23
  • Because I want to format the error messages in a certain way... – Theflex Mar 15 '16 at 11:49
  • You can do this with '' by specifying a `rendererType` and implementing a custom renderer which extends `MessagesRenderer`. – unwichtich Mar 15 '16 at 11:53
  • @unwichtich : Thanks but I would prefer to understand what did I do wrong, because it should work the way I tried. I saw people doing quite the same thing, and I really don't see what I did wrong. – Theflex Mar 15 '16 at 19:24

0 Answers0