1 Reply Latest reply on Oct 3, 2007 7:17 PM by Pete Muir

    Response.addCookie() not working in event model

    Monkey Den Master

      Could someone tell me why this code wouldn't write the cookie once a Seam event is raised? Appears to be something odd with the way the response is being handled. Is there something that resets the response when we enter the Seam event model?


      @Observer("org.jboss.seam.postAuthenticate")
       public void processRememberMe(){
       User user = (User)Component.getInstance("user", false);
       UserAccountBase userAccnt = (UserAccountBase) Contexts.getSessionContext().get("userAccount");
       FacesContext ctx = FacesContext.getCurrentInstance();
       String hash = encrypt(user.getUserName() + "." + user.getUserPassword());
       Cookie cookie = new Cookie("userKey", hash);
       cookie.setPath("/");
       cookie.setMaxAge(31536000);
       HttpServletResponse res = (HttpServletResponse)ctx.getExternalContext().getResponse();
       res.addCookie(cookie);
       userBO.addLoginCookie(hash, userAccnt.getUserKey());
       }