I am having the same problem. On my login page there is a "remember me"
checkbox and if the user clicks and then submits the login page then the
cookie is successfully stored. However if they arive to the page and they
already have that cookie(it just pre-fills the username field) then they are
allowed to unclick the box and then submit the form so that it will remove
the cookie. However, this is not working. Here is my code:
private void rememberMe()
{
Cookie cookie = getRememberMeCookie();
if(cookie == null)
{
cookie = new Cookie("PACKET_TRACKER_USERNAME",
userName);
}
cookie.setPath("/");
cookie.setMaxAge(Integer.MAX_VALUE);
((WebResponse)getRequestCycle().getResponse()).addCookie(cookie);
}
private void forgetMe()
{
Cookie cookie = getRememberMeCookie();
if(cookie != null)
{
cookie.setMaxAge(0);
((WebResponse)getRequestCycle().getResponse()).addCookie(cookie);
}
}
private Cookie getRememberMeCookie()
{
Cookie[] cookies =
((WebRequest)getRequestCycle().getRequest()).getCookies();
if(cookies != null)
{
for(int i = 0; i < cookies.length; i++)
{
if(cookies[i].getName().equalsIgnoreCase("MYAPP_USERNAME"))
{
return cookies[i];
}
}
}
return null;
}
Johan Compagner wrote:
>
> i have no idea then what goes wrong
> especially if it is just one request not a redirect one.
>
> you could try to clean the cookes by directly using the httpresponseobject
> yes.
> Just that that one from the WebResponse
>
> johan
>
>
> On Wed, May 7, 2008 at 5:00 PM, Andrew Broderick <
> [EMAIL PROTECTED]> wrote:
>
>> Tried that, and it didn't make any difference
>> (getRequestCycle().setRedirect(false)).
>>
>> The page is called via a BookmarkablePageLink. Debugging reveals that the
>> constructor, below, is called every time the link is clicked, so it isn't
>> an
>> issue of the code not being called. I also tried calling it via a
>> <wicket:link> as well - no dice.
>>
>> Earlier, someone mentioned something about "pushing" to the
>> HttpServletResponse object. What does this mean, exactly?
>>
>> Thanks
>>
>> -----Original Message-----
>> From: Johan Compagner [mailto:[EMAIL PROTECTED]
>> Sent: Wednesday, May 07, 2008 2:24 AM
>> To: [email protected]
>> Subject: Re: forcing cookies to expire
>>
>> how is that page called/created?
>>
>> if you do this:
>>
>> public SignOut()
>> {
>> clearCookie(Register.REMEMBER_ME_COOKIE);
>> getSession().invalidate();
>> getRequestCycle().setRedirct(false)
>> }
>>
>> what then
>>
>> On Tue, May 6, 2008 at 4:16 PM, Andrew Broderick <
>> [EMAIL PROTECTED]> wrote:
>>
>> > Hi,
>> >
>> > clearCookie() is called in the constructor of a page called SignOut.
>> The
>> > entire constructor is:
>> >
>> > public SignOut()
>> > {
>> > clearCookie(Register.REMEMBER_ME_COOKIE);
>> > getSession().invalidate();
>> > }
>> >
>> > As I mentioned the cookie is never cleared. Is there something else I
>> need
>> > to do?
>> >
>> > Thanks
>> >
>> > -----Original Message-----
>> > From: Johan Compagner [mailto:[EMAIL PROTECTED]
>> > Sent: Monday, May 05, 2008 5:58 PM
>> > To: [email protected]
>> > Subject: Re: forcing cookies to expire
>> >
>> > When is that clear cookie called?
>> > Can you follow that call a bit more, is it pushed to the
>> > httpservletresponse object?
>> >
>> > On 5/5/08, Andrew Broderick <[EMAIL PROTECTED]> wrote:
>> > > Hi,
>> > >
>> > > I am trying to manage cookies in Wicket. I can create them and read
>> them
>> > no
>> > > problem, but forcing expiry by setting maxAge=0 does not seem to be
>> > working.
>> > > Here is the code:
>> > >
>> > > Set cookie:
>> > >
>> > > public void setRememberMeCookie(String username)
>> > > {
>> > > Cookie cookie = new Cookie(REMEMBER_ME_COOKIE, username);
>> > > cookie.setMaxAge(-1);
>> > > cookie.setPath("/");
>> > > getWebRequestCycle().getWebResponse().addCookie(cookie);
>> > > }
>> > >
>> > > Clear cookie:
>> > >
>> > > private void clearCookie(String name)
>> > > {
>> > > Cookie cookie =
>> > > getWebRequestCycle().getWebRequest().getCookie(name);
>> > > cookie.setMaxAge(0);
>> > > getWebRequestCycle().getWebResponse().addCookie(cookie);
>> > > }
>> > >
>> > > The code is definitely called. However, the cookie remains. What am I
>> > doing
>> > > wrong?
>> > >
>> > > Thanks
>> > >
>> > > _______________________________________________________
>> > >
>> > > The information in this email or in any file attached
>> > > hereto is intended only for the personal and confiden-
>> > > tial use of the individual or entity to which it is
>> > > addressed and may contain information that is propri-
>> > > etary and confidential. If you are not the intended
>> > > recipient of this message you are hereby notified that
>> > > any review, dissemination, distribution or copying of
>> > > this message is strictly prohibited. This communica-
>> > > tion is for information purposes only and should not
>> > > be regarded as an offer to sell or as a solicitation
>> > > of an offer to buy any financial product. Email trans-
>> > > mission cannot be guaranteed to be secure or error-
>> > > free. P6070214
>> > >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/forcing-cookies-to-expire-tp17067292p17757935.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]