javagwtuibindergwt-activitiesgwt-places

Understanding GWT onModuleLoad


Behold, my first GWT app's EntryPoint impl:

public class MyModule implements EntryPoint {
    private SimplePanel mainPanel = new SimplePanel();

    @Override
    public void onModuleLoad() {
        // Extract all root-level dependencies from the injector.
        // Using Gin here.
        EventBus eventBus = injector.getEventBus();
        PlaceController placeController = injector.getPlaceController();
        SignInEventListener signInEventListener = injector.getSignInEventListener();
        PlaceHistoryMapper placeHistoryMapper = injector.getPlaceHistoryMapper();

        // Start the activity manager.
        activityManager = new ActivityManager(signInEventListener, eventBus);
        activityManager.setDisplay(mainPanel);

        // Start the place history mapper.
        placeHistoryHandler = new PlaceHistoryHandler(placeHistoryMapper);
        placeHistoryHandler.register(placeController, eventBus, startingPlace);

        // Add the main panel to the RootPanel.
        RootPanel.get().add(mainPanel);

        // Navigate to the place represented by the current URL, otherwise the startingPlace.
        placeHistoryHandler.handleCurrentHistory();
    }
}

Several questions:

  1. My call to the placeHistoryHandler's register(...) method is showing up as being deprecated. Why is it deprecated and what should it be (as of GWT 2.5.1)?
  2. Is there one RootPanel per module/EntryPoint or is there only one RootPanel per GWT app (regardless of how many modules you have)?
  3. What is the connection/relation between the mainPanel (above) that itself has been added to the RootPanel, and the AcceptsOneWidget that gets passed into each AbstractActivity#start method?

Solution

    1. Look here: GWT deprecated: PlaceHistoryHandler.register?
    2. The RootPanel is most likely the <body> element. So there is exactly one.
    3. In most cases you will add one AcceptsOneWidget to the RootPanel. Your Activity has to create its view and set it into the AcceptsOneWidget passed to the start()

    Take a look at the Activity and Places section of gwtproject.org