欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2024-01-26 08:50:52
...

源文转自: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