Quantcast

add cookie on an ajax request

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

add cookie on an ajax request

Decebal Suiu
Hello

I need some help from you.
I have a modal window with panel (X) that has two ajax links (list/grid view mode). on click I want to save a cookie and to refresh some listpanel and gridpanel from X panel. each list and grid panel has the visibility based on the value from cookie.

Ex:
public void onClick(AjaxRequestTarget target) {
   findParent(FileBrowser.class).viewModeChanged(target);
   target.addComponent(ViewModeSelector.this);
                               
  // add cookie
  WebResponse webResponse = (WebResponse) getRequestCycle().getResponse();
  Cookie cookie = new Cookie("display-browser", "grid");
  webResponse.addCookie(cookie);
}

and in grid panel (for example) I do something like this:
public boolean isVisible() {
   String display = "grid";
   Cookie cookie = ((WebRequest) getRequestCycle().getRequest()).getCookie("display-browser");
   if (cookie != null) {
      display = cookie.getValue();
  }
                               
  System.out.println("in grid > " + display);
  return "list".equals(display);
}

My problem is that after onclick in isVisisble  I don't see the new value (grid) added in onclick (I see the old value).I think it's something related to ajax but I don't know what.

Any advice is welcome,
Decebal

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

add cookie on an ajax request

Decebal Suiu
I don't know if my question is a silly question or people are so busy :) From your silence I understand that it's not any problem to add a cookie on an ajax call. I will create a quick start project to test the problem in isolation.

Thanks in advance,
Decebal
Loading...