`
flashcloud
  • 浏览: 189270 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

MVP For GWT 系列资料转载八:Swapping DIVs technique for navigation with gwt-presenter

    博客分类:
  • GWT
 
阅读更多

源文转自:Swapping DIVs technique for navigation with gwt-presenter

 

I have previously written about navigation in gwt-presenter using the DeckPresenter or WidgetContainerPresenter approaches. Those techniques work well for swapping out views in one portion of the page, and could be applied to the whole page, as well; however, here’s another simpler technique for situations in which you need to swap between totally unrelated views. For example, my main app has a header, footer, and content area in which views are swapped out using a WidgetContainerPresenter. However, I also need to replace the whole page (header, footer, and all) for a user registration page. To do this, I simply created two DIVs in the HTML host page:

 

<div id="roa-registration"></div>
<div id="container"></div>

 

My main AppPresenter loads all the presenters up front and fires a PlaceRequestEvent to the user registration presenter for new users. For existing users, it fires a PlaceRequestEvent based on the URL or to the default presenter if the URL is empty.

 

...
	public void go(final HasWidgets container)
	{
		this.container = container;
		loadMain();
		hideSplash();
		if (roaModel.getLoginInfo().getUser() != null)
		{
			showMain();
			String currentPlace = History.getToken();
			if ("".equals(currentPlace))
			{
				goToDefaultView();
			}
			else
			{
				// Load requested page
				placeManager.fireCurrentPlace();
			}
		}
		else
		{
			showRegistration();
		}
	}

	private void showRegistration()
	{
		// New user must register
		eventBus.fireEvent(new PlaceRequestEvent(new PlaceRequest(
			UserRegistrationPresenter.PLACE)));
	}

	private void hideSplash()
	{
		DOM.removeChild(RootPanel.getBodyElement(), DOM
			.getElementById(RoaStyles.ID_SPLASH));
	}

	private void loadMain()
	{
		// Hide while loading
		 DOM.setStyleAttribute(RootPanel.get(RoaStyles.CONTAINER_ID)
		 .getElement(), "display", "none");
		container.clear();
		HeaderPanel headerPanel = new HeaderPanel(roaModel.getLoginInfo());
		headerPanel.add(messagePresenter.getDisplay().asWidget());
		container.add(headerPanel);
		...
		container.add(bodyPanel);
		container.add(new FooterPanel());
	}

	private void showMain()
	{
		// Set GWT container visible
		DOM.setStyleAttribute(RootPanel.get(RoaStyles.CONTAINER_ID)
			.getElement(), "display", "block");
		// Load initial data
		prayerListService.refreshPrayerLists();
	}

	private void goToDefaultView()
	{
		// Nothing in URL, load default page
		eventBus.fireEvent(new PlaceRequestEvent(new PlaceRequest(
			ManageListsPresenter.PLACE)));
	}

 

Finally, I toggle the visibility of the two DIVs in the user registration presenter’s revealDisplay() method, which gets called in response to a PlaceRequestEvent. In addition, I call a hideDisplay() method in the presenter’s onBind() method (called from the constructor), so that its initial state is hidden.

 

@Override
public void revealDisplay()
{
	super.revealDisplay();
	RootPanel.get(RoaStyles.CONTAINER_ID).setVisible(false);
	RootPanel.get(RoaStyles.REGISTRATION_CONTAINER_ID).setVisible(true);
}

public void hideDisplay()
{
	RootPanel.get(RoaStyles.REGISTRATION_CONTAINER_ID).setVisible(false);
}

 

The downside to this technique is that it would be a pain to manage with more than a few DIVs, as each presenter would have to know how to show itself and hide the others; however, for swapping between completely different page layouts, I think it’s easier than creating nested WidgetContainerPresenters (if that would even work). On the plus side, multiple presenters can use each layout (DIV), and most applications are likely to need only a handful of completely distinct page layouts. YMMV.

分享到:
评论

相关推荐

    GWT简介.docx

    5. **异步通信(Ajax)**:GWT内置了异步通信机制,通过GWT的RequestBuilder或GWT-RPC(Remote Procedure Call)实现与服务器的无缝交互,实现页面的无刷新更新。 6. **本地化支持**:GWT支持多语言环境,开发者...

    gwt-maven-plugin:开始使用Maven构建GWT项目

    gwt-maven-plugin 该插件旨在通过提供两种特定的打包方式: gwt-lib和gwt-app ,使使用Maven构建GWT项目更加容易。 基本用法 将插件添加到您的POM并启用扩展: &lt; groupId&gt;net.ltgt.gwt.maven&lt;/ groupId&gt; ...

    gxt-2.1.1-gwt2 最新的

    gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2

    gwt-dev-plugin-x86-对ie浏览器使用

    3. **UI构建**:GWT提供了丰富的Widget库,允许开发者构建复杂的用户界面,同时支持MVP(Model-View-Presenter)和MVVM(Model-View-ViewModel)设计模式。 4. **国际化和本地化**:GWT支持多语言应用,可以轻松地...

    gwt-maven-plugin:旧版GWT Maven插件

    现在,该插件被认为是legacy GWT maven plugin (又名mojo GWT maven插件),而新插件被认为是new generation GWT maven plugin (又名tbroyer GWT maven插件)。 仍然支持旧版maven插件,但强烈建议将新插件用于新...

    最好的gwt-ext学习资料

    ### Gwt-Ext:强大的网页开发控件库详解 Gwt-Ext,作为一个结合了Google Web Toolkit(GWT)和ExtJs的高级网页开发控件库,为纯Java语言的富互联网应用程序(RIA)开发提供了强有力的支持。尤其对于初学者而言,Gwt...

    gwt-dev-plugin for IE、FireFox、Chrome

    2. **gwt-dev-plugin-x86.msi**:这是一个Windows安装程序包,用于32位系统。MSI是Microsoft Installer的文件格式,用户可以通过双击此文件进行标准的Windows安装过程。 3. **gwt-dev-plugin.xpi**:这是Firefox...

    gwt-servlet-2.3.0.jar

    GWT-Servlet是GWT框架的一部分,主要负责处理服务器端的交互。`gwt-servlet-2.3.0.jar`是GWT 2.3.0版本的Servlet库,这个库包含了运行GWT应用所需的服务器端组件。 在GWT的应用程序中,客户端部分通常由JavaScript...

    gwt-widgets-server1.1.jar

    GWT整合Spring时需要这个包,在官网上没有最新的jar包,这是自己用jar命令生成的,并测试可以使用。

    gwt-ex t学习必备资料

    gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-...

    gwt-comet-jar包+实例+source.jar包,

    里面东西很多,都是关于GWT-COMET的内容,实现gwt的服务器推技术,包括gwt-comet-examples-1.2.3:google官网上的Test实例;gwt-comet-1.2.3.jar:jar包,gwt-example:聊天实例源代码(.java的),gwt-event-source...

    gwt-2.5.1.zip

    GWT-2.5.1是GWT的一个版本,包含了该框架的库文件和其他必要的组件。 在安装GWT-2.5.1之前,确保你的系统已经安装了Java Development Kit(JDK),因为GWT是基于Java的。接下来,我们将详细介绍GWT的安装步骤: 1....

    gwt-rpc-serialization:重用 gwt-storage 和 gwt-rpc 序列化技术在客户端序列化对象的概念证明

    本文将深入探讨GWT-RPC(Remote Procedure Call)和GWT-Storage的序列化技术,并结合给定的标题和描述,展示如何在客户端实现对象的序列化,以及这个概念证明的意义。 **GWT-RPC序列化** GWT-RPC是GWT提供的一种...

    GWT-Developer-Plugin

    GWT-Developer-Plugin

    gwt-2.8.2 SDK 最新下载 google web toolkit

    GWT-2.8.2是该SDK的一个版本,提供了最新的特性和改进,旨在简化Web应用的开发流程,提高开发效率。 GWT的核心理念是"Write Once, Run Everywhere",它将Java代码编译成优化过的JavaScript,确保在各种浏览器上都能...

    gwt入门-gwt从这里开始

    解压后的目录中包含了如 `gwt-dev-windows.jar` 和 `gwt-servlet.jar` 等库文件,它们是 GWT 开发和运行所必需的。`gwt-dev-windows.jar` 包含了 GWT 的开发工具,而 `gwt-servlet.jar` 用于服务器端支持。 9. **...

    Gwt-Ext基础-中级-进阶

    这个压缩包包含的资源是关于Gwt-Ext的基础、中级和进阶学习资料,适合想要深入理解和应用Gwt-Ext的开发者。 在"基础篇"中,你将学习到以下知识点: 1. **GWT概述**:Google Web Toolkit是一个用于构建高性能、跨...

    gwt-user.jar

    gwt-user.jar 大小:2.86 MB

    Gwt-ext学习笔记

    在阅读《Gwt-ext学习笔记.pdf》这份资料时,应重点学习上述知识点,并通过实践项目来加深理解。同时,关注Gwt-ext的更新和社区资源,以便获取最新的API信息和最佳实践。不断练习和探索,你将能够熟练运用Gwt-ext构建...

Global site tag (gtag.js) - Google Analytics