MVP For GWT 系列资料十:Loading a default view on startup with gwt-presenter

源文转自:Loading a default view on startup with gwt-presenter

 

As shown in Chris Lowe’s GWT MVP example, I’ve been using getPlaceManager().fireCurrentPlace() in my EntryPoint class to show the initial view after all presenters are loaded. This works fine if there is a history token (placeId) in the URL; however, on initial load, my URL is empty, so I want to navigate to the default view and mark the Place in History (I chuckle every time I use that phrase). The simplest way to do this is to fire a PlaceRequestEvent, so my GWT EntryPoint class now concludes with this:

 

// Load PlaceManager so it can start listening
PlaceManager placeManager = injector.getPlaceManager();

String currentPlace = History.getToken();
if ("".equals(currentPlace))
{
	// Nothing in URL, load default page
	injector.getEventBus().fireEvent(
			new PlaceRequestEvent(new PlaceRequest(
					ManageListsPresenter.PLACE)));
}
else
{
	// Load requested page
	placeManager.fireCurrentPlace();
}

 

My default presenter is contained within a WidgetContainerPresenter, and gwt-presenter calls the appropriate methods to reveal my default view, set it as the current presenter in the container, and update the URL in the address bar. Slick.

你可能感兴趣的:(gwt)