如何使用StateManager gxt 3

时间:2012-10-16 10:54:09

标签: java gxt

我正在尝试使用以下方法获取CookieProvider的值:

public void getValue(){
    StateManager.get().get("idReg", String.class, new Callback<String, Throwable>() {            
    public void onFailure(Throwable reason) {
        state = "";
    }
    public void onSuccess(String result) {
    state = result; 
        });    
}

发出以下例外:

java.lang.NullPointerException at
com.google.web.bindery.autobean.gwt.client.impl.JsniCreatorMap$.create$(JsniCreatorMap.java:44) 
at com.google.web.bindery.autobean.gwt.client.impl.AbstractAutoBeanFactory.     
create(AbstractAutoBeanFactory.java:38) at    
com.sencha.gxt.state.client.StateManager.getDefaultStateInstance(StateManager.java:90)
at com.sencha.gxt.state.client.StateManager$1.onSuccess(StateManager.java:73)
at com.sencha.gxt.state.client.StateManager$1.onSuccess(StateManager.java:1)
at com.sencha.gxt.state.client.CookieProvider.getValue(CookieProvider.java:54)
at com.sencha.gxt.state.client.StateManager.get(StateManager.java:64)
at com.rfrate.exrate.client.NorthComponent.setComboValue(NorthComponent.java:46)
at com.rfrate.exrate.client.NorthComponent.asWidget(NorthComponent.java:102)
at com.google.gwt.user.client.ui.Widget.asWidgetOrNull(Widget.java:46)
at com.sencha.gxt.widget.core.client.container.Container.add(Container.java:72)
at com.rfrate.exrate.client.ExRate.createNorth(ExRate.java:52) 
at com.rfrate.exrate.client.ExRate.onModuleLoad(ExRate.java:97) ... 9 more

任何人都可以提供一个代码示例来读取和写入cookie中的变量String值吗?

1 个答案:

答案 0 :(得分:0)

我不确定是否使用StateManager,但只是读取写入cookie:

写:

  //javax.servlet.http.Cookie
Cookie localUserId = new Cookie("cookieName", user_info.getLocalDataId());nick_name.setPath("/");
nick_name.setMaxAge(36 * 24 * 60 * 60);
  //appengine specific
this.getThreadLocalResponse().addCookie(localUserId);

读:

    //com.google.gwt.user.client.Cookies;
Cookies.getCookie("cookieName"));