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.

發佈了33 篇原創文章 · 獲贊 1 · 訪問量 7225
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章