2012-10-16 54 views
2

我試圖讓CookieProvider的值下面的方法:如何使用StateManager GXT工作3

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中的變量字符串值?

回答

0

我不知道如何使用StateManager,但讀寫餅乾很簡單:

寫:

//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")); 
+0

在GXT 2.X是一個很好的方式:StateManager.get()。 getString() – rfrate