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()); }
Should be fine - are you sure you are writing to the correct Response object? Use your debugger to take a look.