tags:

views:

562

answers:

3

I have a project which will be made up mostly of Java Servlets, JSP/Html pages, and some regular javascript. However, there are some screens which will be too complex to do in just javascript, so I will want to use GWT for that.

Is it possible to do this, so there are multiple EntryPoint classes in the same project? Then, depending on which page is being loaded I will load the appropriate javascript file?

I was thinking that perhaps, the RootPanel.get() function will be used to check if certain <div>s with a given ID exist. For example, if the signup div exists, load the sign up GWT control, if 'search' div exists then load Search, but this will make the javascript file very large unnessarily. I'd much rather each component be in its own javascript file.

Is that possible?

+1  A: 

I think it would be best to separate pages into GWT modules. If you will use RootPanel.get() to check if specific slot (DIV or other element) exists your module will hold all of your UI, so client will load whole module, only accessing one page - which well be unnecessary overhead. You can place common code in some module which all of your pages modules will inherit from.

RootPanel.get() is better for you to have sets of widgets (logical panels in your UI e.g. menu, main content, etc.) and you can place them in proper slots on page.

Example structure in your app would look like (see question in comment):

- gwtui
-- common (module1)
--- client
---- widgets (eg. common widgets)
---- ...
---- ApplicationService.java
---- ApplicationServiceAsync.java
--- public
---- images (common images etc.)
---- css (common style)
---- ...
--- server
---- ...
---- ApplicationServiceImpl.java
--- GwtCommon.gwt.xml
-- expenses (module2)
--- client
---- ExpensesEntrypoint.java
--- public
--- server
--- GwtExpenses.gwt.xml (inherits GwtCommon, entry point ExpensesEntrypoint)
-- reports (module2)
--- client
---- ReportsEntrypoint.java
--- public
--- server
--- GwtReports.gwt.xml (inherits GwtCommon, entry point ReportsEntrypoint)

Note that you can use one service in all modules, as well in common module you might don't have to create entry point (but I'm not 100% sure, in some old project I had to create empty entry point, but don't remember exact reason - sorry)

That worked for us.

I certainly would like to hear different opinions.

Konrad
I do want to keep them in separate modules, but how can you do that? I thought one project could have only 1 EntryPoint class, or can you have multiple? if you can show a code sample of how to have 2 modules it'll be fantastic..
Click Upvote
I edited original post to showing my solution with multiple modules. If need fuhrer explanations let me know. And again - I'm not saying that's the best approach, just I don't know better one yet.
Konrad
+1  A: 

I suggest you look at Optimizing a GWT Application with Multiple EntryPoints.

cletus
+1  A: 

Here's a five minute lightning talk I did on this exact subject: http://www.youtube.com/watch?v=0DuR9xDvrHA&amp;feature=channel_page

Understandably, you cannot put a lot of information into 5 minutes, so hopefully this will give you enough to get going, but if you have further questions, please feel free to ask.

I intend to make more code samples available but I haven't found the time.

Jack Leow