views:

72

answers:

3

I have a widget written in GWT. In the implementation of EntryPoint, I have the widget load a controller and a view that is tied to that controller. I add this view to the RootPanel and it works fine.

public class EntryImpl implements EntryPoint {

  SimplePanel simplePanel;
  View view;
  Controller controller;
  public final void onModuleLoad()
    {
        controller = createController();
        view = createViewForController(controller);
        simplePanel = new SimplePanel();
        simplePanel.add(view);
        RootPanel.get().add(simplePanel);

    }
}

Something like above. Now I want to change the view and controller, say if the user clicks a button to load a different view. I tried something along the lines of adding an Anchor and handling the ClickEvent as follows:

public void onClick(Widget sender) {
  simplePanel.remove(view);
  controller = createController();
  view = createViewForController(controller);
  panel.add(view);
}

Is this the right way to go about doing this, or is there a better way? So far, this isn't working for me-- my new view is not showing up.

Thanks

+1  A: 

You can use DeckPanel and switch the view using showWidget(index) method. Enabling deck panel's animations can improve usability.

morisil
A: 

what is panel in your OnClick event? if you just want to see the view you can get the root panel and see it RootPanel.get().add(view), Adding a div in the base HTML page may serve your purpose , if you have div you can add your view inside that div by RootPanel.get("div").add(view)...

Saket Bansal
A: 

You can use mvp pattern to control view transition (I have not used it yet)

http://code.google.com/intl/en/webtoolkit/articles/mvp-architecture.html

david