複数ページの使用

GWTは,基本一つのページでごにょごにょやりますが,gwt-multipage というmoduleを使用すると割と簡単に複数ページを実装できます.
使い方を簡単に説明すると.
  1. Google Web Toolkit module file (???.gwt.xml)
    サイトからモデュールをダウンロードし,gwtmulitpage-core.jar をビルドパスに追加.
    次に,???.gwt.xmlを編集. gwtmulitpage module をinherit し,entry-point要素のclass にEntrypointDispatcherを指定します.
     <module>
            <!-- Inherit the core Web Toolkit stuff.  -->
            <inherits name='com.google.gwt.user.User'/>
    
            <!-- Inherit the gwt-multipage module -->
            <inherits name='org.gwtmultipage.gwtmultipage'/> <!--ここ-->
    
            <!-- Use this EntryPoint instead of your own one. -->
            <entry-point class='org.gwtmultipage.client.EntrypointDispatcher'/>> <!--ここ-->
     
            <inherits name="com.google.gwt.user.theme.standard.Standard"/>
            <!-- < inherits name="com.google.gwt.user.theme.chrome.Chrome"/>  -->
            <!-- <inherits name="com.google.gwt.user.theme.dark.Dark"/>  -->
            
    </module>
    
  2. EntryPoints
    MyMultipageEntryPoint.htmlとMyMultipageEntryPoint2.htmlを作成します.
    次に,EntryPointとしたいクラスにMultipageEntryPoint アノテーションを加え,URLとの結びつけを行うとこれで完了です.
    (¥¥¥¥?gwt.codesvr=127.0.0.1:9997)?をつけていることで,dev モードでも動作する(URL指定が正規表現なため).
    package org.gwtmultipage.sample.client;
    
    import org.gwtmultipage.client.MultipageEntryPoint;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.RootPanel;
    
    @MultipageEntryPoint(urlPattern = "MyMultipageEntryPoint.html(¥¥¥¥?gwt.codesvr=127.0.0.1:9997)?")
    public class MyMultipageEntryPoint implements EntryPoint {
    
            public void onModuleLoad() {
                    Label label = new Label("MyMultipageEntryPoint");
                    RootLayoutPanel.get().add(label);
            }
    
    }
    
    package org.gwtmultipage.sample.client;
    
    import org.gwtmultipage.client.MultipageEntryPoint;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.RootPanel;
    
    @MultipageEntryPoint(urlPattern = "MyMultipageEntryPoint2.html(¥¥¥¥?gwt.codesvr=127.0.0.1:9997)?")
    public class MyMultipageEntryPoint2 implements EntryPoint {
    
            public void onModuleLoad() {
                    Label label = new Label("MyMultipageEntryPoint2");
                    RootLayoutPanel.get().add(label);
            }
    
    }