原始的gwt开发模式在大型项目或复杂页面中并不适用,这促使了Gwt Hostpage模块的诞生。
1.简介 & Features
GWT Hostpage 设计意图是:将页面/模块 真正组件化,不同页面按需要把相应模块装载进来。
提供功能:a.创建组件:页面可以随便创建导入module的component
b.订阅模块的事件:不同模块间,可以相互通信,发布时间与订阅。
2.核心 & Demo
2.1 how to create a component
- public class Index implements EntryPoint {
- public void onModuleLoad() {
- //the ModuleName , like Login.gwt.xml
- String loginModuleName = "com.test.user.login.Login";
- //new a container to set the component(widget)
- SubModuleContainer container = new SubModuleContainer();
- //you can use construct args to chose which component to create
- String args[] = {"LoginForm"};
- //arg : moduleName ,componentId ,container element ,construct args
- HostpageFacade.createComponent(loginModuleName, "LoginComponent",
- container.getElement(), args);
- //add the container in Index module
- RootPanel.get().add(container);
- }
- }
构造一个组件非常简单:模块名,构造参数。同时,给创建了的组件一个id,以及要放置的位置。
2.2 把组件创建工厂往hostpage中注册。以便以他模块能获得该factory而创建
2.2 how to registe a component factory in Hostpage module
- public class Entry implements EntryPoint {
- //
- Exporter exporter = (Exporter) GWT.create(Exporter.class);
- //module name
- String compTypeName = GWT.getModuleName();
- public void onModuleLoad() {
- // new a component facotry
- LoginuserFactory factory = new LoginuserFactory();
- // registe to Hostpage module
- HostpageFacade.registerComponentFactory(compTypeName, factory);
- }
- //the factory extend a ComponentFactory
- class LoginuserFactory extends ComponentFactoryImpl {
- //over write the getModuleName
- protected String getModuleName() {
- return GWT.getModuleName();
- }
- //overwrite , create the component in LoginModule
- protected Widget createComponent() {
- LoginMain loginComponent = new LoginMain(super.args);
- super.registerComponent(exporter.doExport(loginComponent),
- loginComponent.getElement());
- return loginComponent;
- }
- }
- public interface Exporter extends IExporter {
- JavaScriptObject doExport(LoginUserService factory);
- }
- }
把组件创建工厂往hostpage中注册。以便以他模块能获得该factory而创建
3.url
http://code.google.com/p/macaufly-gwt-tool/downloads/list