1 2 Previous Next 15 Replies Latest reply on Nov 6, 2010 4:05 PM by tbryan

    How can I clear facesMessages?

    cardel.ka.jelinek.seznam.cz

      I make some steps in my fuction and inside this function I update some entities. I use home objects for them, so after every update of entity shows predefined message      Successfully updated. If I make 3 changes on 3 entities I have 3 same messages.


      I would like to know, how can I clear all faces messages and show only my own message. I don´t want to override update method of home object.


      I tried this:



      .
      .
      @In private FacesMessages facesMessages;
      .
      .
      
         facesMessages.clear();
         facesMessages.getCurrentGlobalMessages().clear();
         facesMessages.getCurrentMessages().clear();
      .
      .
      
      



      But with no effect.


      Any ideas?

        • 1. Re: How can I clear facesMessages?
          vasana

          Do you have those messages defines in your Entity class?

          • 2. Re: How can I clear facesMessages?
            cardel.ka.jelinek.seznam.cz

            I don´t understand You. Why should I have some messages in my entity class?
            For example I have UserHome home object for my User entity. And in messages_en.properties I have messages User_created, User_updated, User_deleted. This messages are automatically showed if I make some changes on User entity and call UserHome.persist(), UserHome.update().
            But In my case I have some action and in this action I am changing more objects. Finally I call UserHome.update(), FtpUserHome.update() ... So I have one message for every update and on the screen is:


            "User 'blabla' was updated"
            "Ftp user 'blabla' was updated"



            But I want to clear all these messages on the end of my action a show only the last one, or show another one.


            Thanks

            • 3. Re: How can I clear facesMessages?
              cardel.ka.jelinek.seznam.cz

              Has anyone some tips?

              • 4. Re: How can I clear facesMessages?
                cardel.ka.jelinek.seznam.cz

                I have debuged my code and I explored, this:


                At the end of my action I have for example 3 messages
                buffered in FacesMessages class, but they are not in facesMessages ArrayList which can be cleared by methods I wrote above, but my messages are in tasks ArrayList. I can browse them, when I am in debug mode, but I don't know how can I clear them.


                At the end of my action I return some outcome and then all of messages from tasks ArrayList are shown.


                • 5. Re: How can I clear facesMessages?
                  stephen

                  RTM!
                  See section 12.2 Home Objects in the Seam reference.
                  The relevant text starts towards the end of the section with The Home object automatically displays faces messages when an operation is successful.

                  • 6. Re: How can I clear facesMessages?
                    cardel.ka.jelinek.seznam.cz

                    I know about this feature. And I am using It. But I asked if it is possible to clear showed messages after persisting object via its Home Object.

                    • 7. Re: How can I clear facesMessages?
                      stephen

                      Then I just don't understand you.


                      You said you want to have the messages removed and I pointed you to a section that describes how you can disable them.


                      What am I missing?

                      • 8. Re: How can I clear facesMessages?
                        cardel.ka.jelinek.seznam.cz

                        No, I want to use this messages, but I want to remove some of showed messages, in some situation.


                        Example:


                          I call UserHome.persist() and message User 'blabla' was created is showed. It is ok.


                        On other page I call CustomerHome.persist() and message Customer 'blabla' was created is showed. It is ok.


                        But I have problem with this:
                        I call UserHome.persist() and CustomerHome.persist() in some action. And this shows me 2 messages User 'blabla' was created and Customer 'blabla' was created. But I want to show only first one in this case.






                        • 9. Re: How can I clear facesMessages?
                          turntwo

                          That doesn't help clear the messages when you don't want them.  I have the same issue - I create several new records, but don't want the facesMessages showing in the UI.  I tried to .clear() them, but to no avail. 

                          • 10. Re: How can I clear facesMessages?
                            cardel.ka.jelinek.seznam.cz

                            I debugged my code and messages from home objects are stored in some buffer in tasks ArrayList in FacesMessages class. There is no method to clear this arraylist.
                            I have overrided problem messages User_created, User_updated, User_deleted so they are now empty. And I show my own message when I need.


                            • 11. Re: How can I clear facesMessages?
                              leesy

                              I wanted to solve the same problem but taking a look through the Seam code, it looks like isn't something you can do from your Home bean.  As you mentioned, when a message is created it goes into a list called tasks.  This is a list of Runnable objects which on being run will take the task and add it to a facesMessages list.  The clear method clears this facesMessage list.  So it looks like the items in the tasks list aren't being called till after the method in your home bean completes.  So it looks like it's going to be a no go.


                              What I plan on doing is override the Home classes persist() method and just do everything the home object does, minus the call to the createMessage() method.

                              • 12. Re: How can I clear facesMessages?
                                alesaudate
                                I was having the same trouble. After I read this forum, I produced a "hack", to get the tasks list and clear it. Below is the code:


                                try {
                                     Field f = messages.getClass().getDeclaredField("tasks");
                                     f.setAccessible(true);
                                     List list = (List) f.get(messages);
                                     list.clear();
                                }
                                catch (Exception e) {}
                                • 13. Re: How can I clear facesMessages?
                                  zahidncst

                                  Above is a good hack..I may try it ..
                                  I solved it by hiding it with css style - visiblity:hidden


                                  I detailed it at http://www.jroller.com/seam

                                  • 14. Re: How can I clear facesMessages?
                                    sinannn

                                    There is a method named afterPhase() in facesMessages component. This method adds new messages to facesMessages' message list and then clear tasks list. If you firstly invoke facesMessages.afterPhase() method and after facesMessages.clear() method, nothing stays in message list.


                                    Another trick is to use rich:messages component. There is a level property of this component and you can select which messages to be displayed by writing into level property WARN,FATAL etc. Surely, if you add your messages to facesMessages with a severity level.

                                    1 2 Previous Next