开发者

GWT - Multiple modules?

I am struggling in getting the structure of my GWT application right. (Am I the only one one who finds that GWT code very easily ends up very messy and unreadable?)

The application is supposed to be an interface to a couple of quite distinct areas - let us say area A and B. At the moment i am trying to implement it as an interface with two tabs - one taking you to area A and one taking you to area B. I do not see how I can have a nice separation of the code needed for the two different areas in this way though - applying the MVP pattern (which I actually do not find that clear how to do in a case of a hierarchic interface like my tabs) I end up having area A and area B code in for instance both the client.view and the client.presenter package:

开发者_Go百科
src
 - main
     - java
         - client
             + event
             - presenter
                 + a_stuff
                 + b_stuff
             - view
                 + a_stuff
                 + b_stuff
 :

I have not been able to find any good examples of how and when to use multiple modules and I am wondering if my case might be one where multiple modules would make sense? How would the code be structured in that case?

Maybe it is relevant to mention that I am using the latest GWT, Maven and IntelliJ IDEA.

Hints would be greatly appreciated, thanks a lot from Stine :)


Here is a more thorough example that helped me get two modules working: http://ashtoncthomas.blogspot.com/2011/02/multiple-modules-in-google-web-toolkit.html

It uses the structure:

src
 - main
     - java
         a_stuff.gwt.xml
         b_stuff.gwt.xml
         - client
              - shared_stuff
              - a_stuff
                   - presenter
                   - view
              - b_stuff
                   - presenter
                   - view

If you want two HTML pages - one for each module (like I did), then you need to create two pages:

war
  page_a.html
  page_b.html

And define your entry points in your two .gwt.xml files, for example (for a_stuff.gwt.xml):

<module rename-to='module_a'>

    ... your stuff here ...

    <entry-point class="main.java.client.a_stuff.A_entry_point"></entry-point>
</module>

Where A_entry_point is a class that implements EntryPoint.

Then, in your HTML pages, only include the module you want (for example, in page_a.html):

<script type="text/javascript" language="javascript" 
        src="module_a/module_a.nocache.js"></script>

Also, if you're using Eclipse, then when you click on "GWT Compile Project", it will ask you to "Add an entry point class", so you must click on the "Add" button in the "Entry Point Modules" section of the GWT Compile window, and add both your entry point modules (a_stuff.gwt.xml and b_stuff.gwt.xml). You can add/remove entry point modules from here as needed, to choose which modules to compile.

The above worked for me. I used it to make two different versions of my website, each in a separate module.


Consider declaring multiple source elements in your yourmodule.gwt.xml file. If no source elements are declared, then by default gwt assumes a "client" declaration. See below:

<!--Default if not declared-->
<source path="client"/>

You can declare multiple source locations like this:

<source path="a_stuff"/>
<source path="b_stuff"/>

Now everything below each source will be compiled. "Client" is only the default, not the rule.


I suggest something like this:

src
 - main
     - java
         + a_stuff
           -client
             - presenter
             - view
             - event
         + b_stuff
           -client
             - presenter
             - view
             - event


Have a look at mvp4g

http://code.google.com/p/mvp4g/wiki/MultiModules

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜