3 Replies Latest reply on Aug 28, 2009 8:11 PM by alankrum

    Duplicate FacesMessage

      Hi!


      I am using Seam 2.0 and have problems with FacesMessage. When a user wants to login I call my Authenticator. If the user is not able to login (because he doesn't exist or the password is incorrect) I am adding a FacesMessage. The problem is, that this message is shown twice on the screen.


      Here is my authenticate method:



      public boolean authenticate()
      {
           try {
                tuser = (Tuser) entityManager.createQuery(
                "select distinct u from Tuser u where u.temail = :email")
                .setParameter("email", identity.getUsername())
                .getSingleResult();
           
                if (!validatePassword(identity.getPassword(), tuser)) {
                     facesMessages.add(FacesMessage.SEVERITY_ERROR, "Anmeldung fehlgeschlagen");
                     return false;
                }
                if(tuser.getTlocked()) {
                     facesMessages.add(FacesMessage.SEVERITY_ERROR, "Anmeldung fehlgeschlagen");
                     return false;
                }
                identity.addRole("user");
                return true;
           } 
           catch (NoResultException eUser) {
                log.info("looking for admin");
                try {
                     Tadmin admin = (Tadmin) entityManager.createQuery(
                     "select distinct a from Tadmin a where a.tusername = :username")
                     .setParameter("username", identity.getUsername())
                     .getSingleResult();
                     if (!validatePassword(identity.getPassword(), admin)) {
                     facesMessages.add(FacesMessage.SEVERITY_ERROR, "Anmeldung fehlgeschlagen");
                          return false;
                     }
                     identity.addRole("admin");
                     return true;
                }
                catch (NoResultException eAdmin) {
                     facesMessages.add(FacesMessage.SEVERITY_ERROR, "Anmeldung fehlgeschlagen");
                     return false;
                }
           }
      }



      If the login is not correct the FacesMessage is shown twice. The next problem: If the user is able to login successfully the second time, then I print a welcome message to the screen. However the failure message of last login is displayed too (but only one not two).


      Now I am thinking, if these messages are two FacesMessages? Normally a FacesMessage should not appear a second  time. It's like, if it stays in the application context once I failed to login. Maybe one of them is something else as a FacesMessage. Is this possible? If yes, where is it created and how can I destroy it?


      I have a template where I set my FacesMessages to be displayed. Here is the code:



      <rich:messages id="messages" globalOnly="true" styleClass="message"
                             errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"
                             rendered="#{showGlobalMessages != 'false'}"/>



      I haven't defined this or a similar tag a second time. I searched every file's text with eclipse's search.


      Did somebody had the same problem or knows a solution?


      Thank you for help!


      regards,
      max.

        • 1. Re: Duplicate FacesMessage

          max meyers wrote on Dec 16, 2008 00:41:


          It's like, if it stays in the application context once I failed to login.


          Sorry, but that's not correct. I tried it another time and found out that it appears twice, if the user fails to login and one of the two messages appears, if the user is able to succesfully login after one failure. After that the message seems to be removed and is not displayed anymore.


          regards,
          max.

          • 2. Re: Duplicate FacesMessage

            Hi max, it also occurred to me, I solved using the clear() method before the add(). facesMessages.clear();

            • 3. Re: Duplicate FacesMessage
              alankrum

              I have a similar problem
              Im adding FacesMessages as well when login in
              When Authenticate returns true my messages do get displayed.
              But when i return false my messages dont get displayed (its like something is clearing FacesMessages).
              I do get two messages that are created automatically by seam (login failed and transaction failed) but no my messeges....


              anyone knows whats going on?