PDA

View Full Version : ContentPanel state problem



micgala
29 Jul 2009, 4:13 AM
Hi.

I am trying to use the contentpanel state for defining the default state of a contentpanel, but I have a problem when the user logout and logins again in the same browser window.

For trying this, please run the following test case, and please let me know what I am doing wrong.

First, execute it, login, then collapse the south panel.
Then logout.

If you close your browser window, then open a new one, and login, everything works fine:
You can see that the south panel will be collapsed by default. This is great.

But if you try logout. and then (keeping the browser opened) click on login, you will see that the south panel is now expanded.

Does anyone know why is that?



public void onModuleLoad() {

final ContentPanel loginPanel = new ContentPanel(new FitLayout());
loginPanel.setHeading("Login");
loginPanel.addButton(new Button("Login", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
for (int i = 0; i < RootPanel.get().getWidgetCount(); i++) {
RootPanel.get().remove(i);
}
Viewport viewPort = new Viewport();
viewPort.setLayout(new FitLayout());

ContentPanel mainPanel = new ContentPanel(new BorderLayout());
mainPanel.setHeading("Main");
mainPanel.addButton(new Button("Logout", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
for (int i = 0; i < RootPanel.get().getWidgetCount(); i++) {
RootPanel.get().remove(i);
}
Viewport viewPort = new Viewport();
viewPort.setLayout(new FitLayout());
viewPort.add(loginPanel);
RootPanel.get().add(viewPort);
}
}));

ContentPanel north = new ContentPanel();
ContentPanel west = new ContentPanel();
ContentPanel center = new ContentPanel();
ContentPanel east = new ContentPanel();
ContentPanel south = new ContentPanel();
south.setStateful(true);
center.setHeading("BorderLayout Example");
center.setScrollMode(Scroll.AUTOX);

BorderLayoutData northData = new BorderLayoutData(LayoutRegion.NORTH, 100);
northData.setCollapsible(true);
northData.setFloatable(true);
northData.setHideCollapseTool(true);
northData.setSplit(true);
northData.setMargins(new Margins(5, 5, 0, 5));

BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 150);
westData.setSplit(true);
westData.setCollapsible(true);
westData.setMargins(new Margins(5));

BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
centerData.setMargins(new Margins(5, 0, 5, 0));

BorderLayoutData eastData = new BorderLayoutData(LayoutRegion.EAST, 150);
eastData.setSplit(true);
eastData.setCollapsible(true);
eastData.setMargins(new Margins(5));

BorderLayoutData southData = new BorderLayoutData(LayoutRegion.SOUTH, 100);
southData.setSplit(true);
southData.setCollapsible(true);
southData.setFloatable(true);
southData.setMargins(new Margins(0, 5, 5, 5));

mainPanel.add(north, northData);
mainPanel.add(west, westData);
mainPanel.add(center, centerData);
mainPanel.add(east, eastData);
mainPanel.add(south, southData);

viewPort.add(mainPanel);
RootPanel.get().add(viewPort);
}
}));

Viewport viewPort = new Viewport();
viewPort.setLayout(new FitLayout());

viewPort.add(loginPanel);
RootPanel.get().add(viewPort);

}

sven
29 Jul 2009, 4:20 AM
When you click on login you recreate all your contentpanel. So they get a new ID. Because they were created also before the autoIncremendId is not starting at 0. States are saved against component IDs. Give your southpanel a unique, but defined, ID.
southPanel.setId("mySouthPanelId");

You should always do that if you use statefull apps (that is also the reason why we disabled it by default)

micgala
29 Jul 2009, 4:22 AM
hmm.

That makes perfect sense to me.

Again, thanks a lot for your quick answer sven.

One big german beer to you :)

Regards,
Michel.

sven
29 Jul 2009, 4:25 AM
And that even without running the code;)