2 Replies Latest reply on May 26, 2008 2:14 PM by kooudy

    How to display more messages for id

    kooudy

      Hello,


      I am trying to display several messages for a control:


      FacesMessages.instance().addToControlFromResourceBundle("idTest", "hello 1");
      FacesMessages.instance().addToControlFromResourceBundle("idTest", "hello 2");
      FacesMessages.instance().addToControlFromResourceBundle("idTest", "hello 3");
      



      but


      <s:div id="idTest">
        <h:message for="idTest""/>
      </s:div>
      


      displays only the very first message:



      hello 1

      So the question is how to display several messages to a control?


      (using sam 1.2.1)
      thanks

        • 1. Re: How to display more messages for id
          stephen

          Interesting one. Both the Sun RI message tag and Trinidad's message tag display only the first message.


          That seems not be standards compliant. JSF spec:


          4.1.7 UIMessage (extends UIComponentBase) encapsulates the rendering of error message(s)
          related to a specified input component.
          ...
          "for" attribute: Identifier of the component for which to render error
          messages.



          You probably have to check for any existing message yourself and append new text :-(


          Maybe you should discuss that on sun's JSF forum?!

          • 2. Re: How to display more messages for id
            kooudy

            I have a workaround:



              public List<String> getFacesMessages(String id) {
                Iterator<FacesMessage> iter = FacesContext.getCurrentInstance()
                    .getMessages(id);
            
                List<String> result = new ArrayList<String>();
            
                while (iter.hasNext()) {
                  FacesMessage msg = iter.next();
                  result.add(msg.getDetail());
                }
            
                return result;
              }