Hans,
 
Adding a cookie to the Response object does not automatically add it to the Request object.  You have to wait until your page finishes so the client can receive the cookie. Requests AFTER that will have the cookie.  In your code, I see you setting a cookie in speichereCookies()  but immediately checking for it in the Request object by invoking ladeCookie() at the end of that method.  The problem is you just created the cookie in the HttpServletResponse and the client didn't get it yet.  Remember the Request and Response objects are not tied together.  Again, the NEXT client submit should have your cookie set and readable in the Request object.
 
Regards,
David Friedman  / [EMAIL PROTECTED]

 -----Original Message-----
From: Hans Sowa [mailto:[EMAIL PROTECTED]
Sent: Monday, January 23, 2006 5:49 AM
To: MyFaces Discussion
Subject: Re: Problem with cookies

Hi all

Can somebody help me?


Thanks in advance.


2006/1/20, Hans Sowa <[EMAIL PROTECTED]>:
Hi

I try to save and load cookies from my Myfaces projekt. I see that I save the cookies in the response but if I load the cookies again I can just find the myfaces cookies but not my ones.

Here is the code which I use:
load code:
    public void ladeCookie() {
        Cookie[] cookies;

        FacesContext faces = FacesContext.getCurrentInstance();

        HttpServletRequest request = (HttpServletRequest) faces
                .getExternalContext().getRequest();

        cookies = request.getCookies();

        for (int i = 0; i < cookies.length; i++) {
            if (cookies[i].getName().equals(SessionUser.DATENBANK)) {
                this.setDatenBank(cookies[i].getValue());
            }
        }
    }

save code:
    public void speichereCookies() {
        Cookie c = new Cookie(SessionUser.DATENBANK, this.getDatenBank());
        c.setMaxAge(-1);
        FacesContext faces = FacesContext.getCurrentInstance ();
        HttpServletResponse response = (HttpServletResponse) faces
                .getExternalContext().getResponse();
        response.addCookie(c);

        this.ladeCookie();

    }

Hope this is enough to find the problem.

Thanks in advance.

Reply via email to