Hi, I have a component which sets a cookie in ajax response, and uses that cookie when rendering upon further requests to the page. But it doesn't work. Is there something wrong on the code below?
I have checked that the cookie is set - Firefox's Web Developer plugin shows it in successive requests. But when debugging, the cookie is not there (null returned). Maybe cookies are not avail at the time of components construction? (Sounds improbable.) Thanks, Ondra package org.jboss.essc.web._cp.pageBoxes; import javax.servlet.http.Cookie; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.request.http.WebRequest; import org.apache.wicket.request.http.WebResponse; /** * About box for the HomePage. * * @author Ondrej Zizka */ public class AboutSmallBox extends Panel { private final static String COOKIE_HIDE_ABOUT_BOX = "essc.hideAboutBox"; public AboutSmallBox( String id ) { super(id); setOutputMarkupId( true ); Cookie cookieHideAbout = ((WebRequest)getRequestCycle().getRequest()).getCookie(COOKIE_HIDE_ABOUT_BOX); if( cookieHideAbout != null ) this.setVisibilityAllowed( false ); // Hides the box and stores that info to a cookie. add( new AjaxLink("dismiss"){ @Override public void onClick( AjaxRequestTarget target ) { target.add( AboutSmallBox.this ); AboutSmallBox.this.setVisible( false ); ((WebResponse)getRequestCycle().getResponse()).addCookie(new Cookie(COOKIE_HIDE_ABOUT_BOX, "true")); } }); }// const }