sjivan / gwt-ext

Automatically exported from code.google.com/p/gwt-ext
0 stars 0 forks source link

CookieProviderConfig setExpires cause JavaScript error #492

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
see http://gwt-ext.com/forum/viewtopic.php?f=8&t=3460

What steps will reproduce the problem?
I tried to reduce the Cookie expiration date from the default 7 days to 1
day only:
Code:
CookieProviderConfig cpf = new CookieProviderConfig();
cpf.setExpires(1); //expire in 1 day from now
cookieProvider = new CookieProvider(cpf);      
Manager.setProvider(cookieProvider);

The first time a cookie is set, the code fails with a JavaScript error
(tested in FF 3.0.4):

Quote:
this.expires.toGMTString is not a function
Ext.state.CookieProvider=function(A){Ext...+((this.secure==true)?";
secure":"")}});

Just using the standard CookieProviderConfig works fine.

Please provide any additional information below.

workaround:

It's a bug in the method setExpires(CookieProviderConfig), the method is
passing the time in millis when it should pass an object Date.

Now you can solve that with a method declaration to the instance overriding
the method setExpires, something like that:
CookieProviderConfig config = new CookieProviderConfig() {
  public void setExpires(int days) {
    Date now = new Date();
    Date expires = new Date();
    long millis = now.getTime() + (1000 * 60 * 60 * 24 * days);
    expires.setTime(millis);
    JavaScriptObjectHelper.setAttribute(jsObj, "expires", expires);
  }
};

config.setExpires(1);
cookie = new CookieProvider(config);
Manager.setProvider(cookie);

Original issue reported on code.google.com by nietz...@gmail.com on 4 May 2009 at 9:08