Since I last checked, you aren’t able to have more than one GWT module on a page. However, each widget is independent, so it makes a lot of sense to package them up as separate modules. Then, you have one module that inherits from all of the other ones, and therefore all the widget code gets executed. Except, sometimes it makes sense for a widget to be on one page and not another. The easies way I have found to do this is to use a span tag with a unique id to mark a page for a component. Sometimes the span tag is where the component places itself–other times it just serves as a
marker for a component which manipulates the DOM in other ways.
The code often looks like this:
RootPanel rp = RootPanel.get(SPAN_ID); if (rp != null) { MyComponent obj = new MyComponent(); rp.add(obj); }
Now, if we’re on a page that this component does not make sense on, it never gets intialized, no network calls are made, etc.
One issue is that if you want to have the component in more than one place on the page, you need to handle that with special cases. You can simply use the same id twice, because it is bad form to have more than one element with the same id on a single page–ids are supposed to be globally unique on a page. If you could use a special tag, that’d be nice, but GWT does not support getElementsByTagName
.