Re: WOCookie - replacing/removing?
Re: WOCookie - replacing/removing?
- Subject: Re: WOCookie - replacing/removing?
- From: David Griffith <email@hidden>
- Date: Wed, 03 Mar 2004 18:31:43 +0100
Hi Benjamin,
Thanks for that suggestion. I'm a little confused by what you are doing
here. If you add a cookie with an expired date, does that remove ALL
cookies with that name?
What I want to do is (and maybe there's a better way):
When the user first hits the initial page, check if there is a cookie
containing their language choice (from a previous visit).
If not, drop one when they choose a language from the list. If there was a
cookie already, load up the language selection based on that and whoooosh...
on to the next page automatically.
However, more importantly, when they are logged in and go to their User
Preferences, and they change the language, I want to update the cookie that
was dropped. I don't care if that means removing the previous one and
dropping a new one, or just changing an existing one.
Suggestions? Thanks for the help..
Dave.
> You can get the cookie sent by the browser from the WORequest - using
> context().request() from a component. I normally send an expired cookie
> with the same path and name to the browser to remove a cookie.
>
>
> ------
>
> public void appendToResponse(WOResponse response, WOContext context) {
>
> if (saveSettings()) {
>
> // save the user's email address
> WOCookie emailCookie = new WOCookie( "email",
> (String)session.user.preferences().valueForKey("kWSLoginEmailAddress")
> );
> emailCookie.setPath("/");
>
> // set the expiration date
> NSTimestamp expires = new
> NSTimestamp().timestampByAddingGregorianUnits(1, 0, 0, 0, 0, 0);
> emailCookie.setExpires(expires);
>
> // add the cookie to the response
> response.addCookie(emailCookie);
>
> } else {
>
> // send expired cookies to clear the older cookies from the user's disk
> as they do not want to save login settings
> WOCookie emailCookie = new WOCookie("email", "none");
> emailCookie.setPath("/");
>
> // set the expiration date to a year ago
> NSTimestamp expires = new
> NSTimestamp().timestampByAddingGregorianUnits(-1, 0, 0, 0, 0, 0);
> emailCookie.setExpires(expires);
>
> // add the cookie
> response.addCookie(emailCookie);
> }
>
> super.appendToResponse(response, context);
> }
>
>
>
> Benjamin
>
>
>
>
> On Wednesday, March 3, 2004, at 01:50 pm,
> email@hidden wrote:
>
>> Once I add a cookie, and it gets stored on the browser, can I replace
>> it
>> with a new value or remove it and re-add it? Not sure how to do this.
>> Have
>> seen the removeCookie(WOCookie cookie) method, but is this what I
>> need, and
>> if so, how do I get the WOCookie to pass to this?
>
>
> Benjamin Miller, Digital Developer
> Watershed Media Centre
> 1 Canon's Road, Harbourside, Bristol, UK. BS1 5TX
> t: +44 (0)117 927 6444, f: +44(0)117 921 3958
> http://www.watershed.co.uk
> iChat/AIM: email@hidden
>
> --
> What's a meaningful and engaging web experience?
> Join in the debate at - http://www.dshed.net/digest
> _______________________________________________
> webobjects-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/webobjects-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.