Duplicate FacesMessage
maxseam Dec 16, 2008 12:41 AMHi!
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.