8 Replies Latest reply on Mar 29, 2008 3:12 PM by Pete Muir

    display messages

    jeremy girard Newbie


      I've got a page with two action performing changes on two different home object.

      So i've got two king of message for persist success.

      I want to have two differents places in my page to display messages, but one place for each kind of message.

      For the moment all the messages are displayed in both messages location.

      Does someone knows how for make the distinction for message type.


        • 1. Re: display messages
          Daniel Roth Apprentice

          I would do:

          <h:message for="name" styleClass="error" />
          <h:message for="name2" styleClass="error" />

          where name/name2 are id:s of some input field (inputText/commandButton etc)
          and then catch the error and show it:

          try {
          } catch(SomeException e) (
             FacesMessages.instance().addToControl("name", "An error occured: #0", e.getMessage())
          } catch(SomeOtherException e) (
             FacesMessages.instance().addToControl("name", "An error that bla bla bla occured: #0", e.getMessage())

          Hope this helps

          • 2. Re: display messages
            Daniel Roth Apprentice

            The second addToControl should have been 'name2', but hopefully that was trivial to see :-)

            Hence, depending on exception, diffrent h:messages are shown.

            • 3. Re: display messages
              jeremy girard Newbie

              Thanks for this answer.

              I want to use something like this but for successuful message generated by the home object

                      CommentHome extends extends AbstractHome<...>
                   public String getCreatedMessage() {
                        return "Votre commentaire a été ajouté";

              How can it specify to the h:message should display only messages from CommentHome ?

              • 4. Re: display messages
                jeremy girard Newbie

                No idea ?
                Is it impossible to filter the display of message from the home object ?

                • 5. Re: display messages
                  Daniel Roth Apprentice

                  Sorry, I haven't used home objects at all :/

                  If you just are trying to filter which messages to show, you could probably iterate over

                  List<FacesMessages> messages = FacesMessages.instance().getCurrentMessages()

                  and remove the ones you don't want to display.

                  • 6. Re: display messages
                    jeremy girard Newbie

                    In fact i do not want to filter message has you describe it.
                    I've got pages that made change on differents entities.

                    I want my message to be displayed exactly were i want in the page.

                    Suppose i have two form in one page. Each form display a successfully created/updated message.

                    I want message from entity 1 to be displayed near the entity 1 form and message from the entity 2 to be displayed near the entity 1 form.

                    Now messages from both entity are displayed near all form. (in each h:messages in fact)

                    • 7. Re: display messages
                      jeremy girard Newbie

                      Is it possible to configure for each home object the target component for message display ?

                      • 8. Re: display messages
                        Pete Muir Master

                        Override createdMessage(), updatedMessage() and deletedMessage() and uses FacesMessages.instance(),addToControl() instead of adding to the global message pool.