论坛首页 Web前端技术论坛

GWT 模块间:组件管理 & 事件处理

浏览 3486 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-12-13  
GWT


原始的gwt开发模式在大型项目或复杂页面中并不适用,这促使了Gwt Hostpage模块的诞生。

 

 1.简介 & Features

GWT Hostpage 设计意图是:将页面/模块 真正组件化,不同页面按需要把相应模块装载进来。

提供功能:a.创建组件:页面可以随便创建导入module的component
          b.订阅模块的事件:不同模块间,可以相互通信,发布时间与订阅。

 

2.核心 & Demo 

2.1  how to create a component
  1. public class Index implements EntryPoint {       
  2.       
  3.     public void onModuleLoad() {       
  4.       
  5.         //the ModuleName , like Login.gwt.xml    
  6.         String loginModuleName = "com.test.user.login.Login";       
  7.                
  8.         //new a container to set the component(widget)    
  9.         SubModuleContainer container = new SubModuleContainer();       
  10.       
  11.         //you can use construct args to chose which component to create    
  12.         String args[] = {"LoginForm"};       
  13.       
  14.         //arg : moduleName ,componentId ,container element ,construct args    
  15.         HostpageFacade.createComponent(loginModuleName, "LoginComponent",       
  16.                 container.getElement(), args);       
  17.                
  18.         //add the container in Index module    
  19.         RootPanel.get().add(container);       
  20.       
  21.     }       
  22. }       

构造一个组件非常简单:模块名,构造参数。同时,给创建了的组件一个id,以及要放置的位置。

 

       2.2 把组件创建工厂往hostpage中注册。以便以他模块能获得该factory而创建

2.2  how to registe a component factory in Hostpage module   
  1. public class Entry implements EntryPoint {       
  2.       
  3.     //       
  4.     Exporter exporter = (Exporter) GWT.create(Exporter.class);       
  5.       
  6.     //module name    
  7.     String compTypeName = GWT.getModuleName();       
  8.       
  9.     public void onModuleLoad() {       
  10.            
  11.         // new a component facotry    
  12.         LoginuserFactory factory = new LoginuserFactory();       
  13.       
  14.         // registe to Hostpage module    
  15.         HostpageFacade.registerComponentFactory(compTypeName, factory);       
  16.       
  17.     }       
  18.       
  19.     //the factory extend a ComponentFactory    
  20.     class LoginuserFactory extends ComponentFactoryImpl {       
  21.       
  22.         //over write the getModuleName    
  23.         protected String getModuleName() {       
  24.             return GWT.getModuleName();       
  25.         }       
  26.       
  27.         //overwrite , create the component in LoginModule    
  28.         protected Widget createComponent() {       
  29.       
  30.             LoginMain loginComponent = new LoginMain(super.args);       
  31.       
  32.             super.registerComponent(exporter.doExport(loginComponent),       
  33.                     loginComponent.getElement());       
  34.       
  35.             return loginComponent;       
  36.         }       
  37.     }       
  38.       
  39.     public interface Exporter extends IExporter {       
  40.         JavaScriptObject doExport(LoginUserService factory);       
  41.     }       
  42. }      
  43.   

把组件创建工厂往hostpage中注册。以便以他模块能获得该factory而创建

 3.url

http://code.google.com/p/macaufly-gwt-tool/downloads/list

论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics