View Full Version : Using 'State' in GXT

19 Nov 2009, 5:42 AM
Hi all,

I'm trying to wrap my head around how the concept of 'state' works in GXT, so far I've only been able to make a contentPanel remember if it was collapsed or not when a page refresh takes place, but any widgets nested within that panel seem to forget their state, even when the setStateful() parameter is true and a stateId has been set.

I'd been lead to believe that a stateful GXT app was achievable 'out of the box', so i'm left wonder exactly 'what' the state for a given component consists of, is it events eg: A collapsed contentPanel. Or does it also contain information like the absolute position of the widget in its parent? Is a data object such as BorderLayoutData required to achieve stateful behaviour?

The API documentation has taken me in circles for the last couple of days so if anyone can offer an overview of how one would achieve a stateful GXT application it would be very appreciated.
I've undertaken the statemanager/ Cookieprovider methodology as shown in the API docs, but at some point I'll need to swap out the Cookie provider with a customised provider as we're producing an application where cookies wouldn't provide the level security we require.

I'm specifically intrested GXT (EXT-GWT 2.0.1), rather than EXT Js as i've seen a number of tutorials offering advice on how to achieve stateful behaviour within EXT Js and they've not really helped me progress at all.

Thanks in advance to anyone who can offer help with this

25 Nov 2009, 2:38 AM
Hi TehLasher,

I have also been left wondering why State doesn't seem to work how I expected it to after reading the API. I can get a 'layouted' panel's collapse state persisting, however anything nested within that or other widgets dont behave stateful. I aware I must explicitly set stateful to true as well as set sateId/id to something unique.

When I read about the existance of State aware widgets in GXT I was hoping that this meant all the particular get/set stateful properties of a widget to be maintained so all I have to do is rely on the default CookieStatemanager to restore them, or implement my own StateManger to simply save/get the statefulness on a per widget basis. For all the GXT widgets that expose a setStateful then surely some sort of state functionality works without any lower-level programming?

7 Dec 2009, 5:50 AM
So has anyone out there experienced state problems or succesfully implementing stateful GXT widgets?

10 Mar 2010, 8:50 AM
Successful implementation of stateful widget:

import java.util.Map;

import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class TestStart implements EntryPoint {

String VALUE = "VALUE";

public void onModuleLoad() {

final TextField<String> textField = new TextField<String>(){

// tell what to do after restore state (eg. set properties or values)
protected void applyState(Map<String, Object> state) {
setValue((String) state.get(VALUE));

// enable state mechanism

// set unique name for Provider in this example for the default CookieProvider

// somewhere in your code set proper values and save state
textField.addListener(Events.KeyUp, new Listener<FieldEvent>() {

public void handleEvent(FieldEvent be) {
textField.getState().put(VALUE, textField.getValue());


11 Jun 2010, 1:37 AM
is their way to save complete panel. How do I restore state if I am using View component

16 Sep 2011, 1:17 AM
State Management is a build-in feature in Gxt. I'm surprised that I could not find an example using States for standard components.

Could anyone provide a basic example how to use States?

16 Sep 2011, 2:00 AM
I wanted a statefull tree like here (http://sencha.com/examples/#asynctree) and experienced some problems.
I got help from our friends here on forum and managed to implement it.

I had to set id for my nodes (in my treepanel case) and to set statefull true.

I haven't tried yet to use state on other components but I think you should take a look over StateManager (http://dev.sencha.com/deploy/gxtdocs/com/extjs/gxt/ui/client/state/StateManager.html) and History (http://raibledesigns.com/rd/entry/gxt_s_mvc_framework) .. to see if it can help you.