views:

5182

answers:

6

I have multiple entry points in the same module.

For example I have an Home entry point for the home page and an Admin entry point for the admin page.

<entry-point class='com.company.project.client.HomeModule'/> 
<entry-point class='com.company.project.client.AdminModule'/>

The way I am setup now - I need to check somt like this in my OnModuleLoad:

if((RootPanel.get("someHomeWidget")!=null)&& 
  (RootPanel.get("someOtherHomeWidget")!=null)) 
{ 
  // do the stuff 
}

in order the the Admin Entrypoint not to be executed when the Home page gets open and the other way around.

Not doing the check above also involves that if I have a div with the same name in both the Home and Admin page whatever I am injecting in it shows up twice on each of them.

This stinks 1000 miles away and is obviously wrong: what's the correct way to do this in people experience?

Any help appreciated!

+3  A: 

The correct way is to have a single entry point per module, that sticks the appropriate widgets in the appropriate divs:

RootPanel panel = RootPanel.get("someHomeWidget");
if (panel) panel.add(new HomeWidget());

panel = RootPanel.get("adminWidget");
if (panel) panel.add(new AdminWidget());

That way it just scans the page looking for any divs you have and inserts the appropriate widget. So your HTML page determines what widgets are displayed when and the GWT code is ready to handle any situation. There's nothing about the above that stinks, it's the way your entry point should be written.

The alternative is if your admin area and normally area are totally different (eg: you want to load them at separate times) then they should be separate modules, with separate entry points.

rustyshelf
In my case home page and admin page need to be loaded at different times (they're different pages!) - so even with a single entry point it wouldn't find the divs and it would throw an exception. On the other end, what's not clear about using different modules is how to config which one should fire with which page.
JohnIdol
Why wouldn't it find the divs? You do realise that you can put the javascript import for GWT on as many pages as you want. So you'd put it on your admin page and have the admin div further down the page. Then you'd also put it on the normal page and have the normal div further down the page.If you have multiple modules on the other hand, you just include the javascript import for the module you want on the page you want, it's pretty simple really.
rustyshelf
+1  A: 

Hi,

Dont consider Admin and home page as different pages. Concept of pages is not applicable to GWT, as there is only one single page, ie single entrypoint. If you want to give effect of different pages, then use URL rewriting features of GWT.

If you do want to use different Entrypoints, then as said in above comment, use different modules.

sbidwai
Thanks - I am not very familiar with URL Rewriting (could you provide some links?) - what is the best approach anyway between this and multiple modules? In a scenario such as the one you describe, why is it possible in the first place to define multiple entrypoints? Are you saying that multiple entrypoints in the same module should never be used?
JohnIdol
Hi John, For URL rewriting, I suggest you to go through entire History related stuff in GWT. Multiple entry points for module based things - Many times, especially for enterprise applications, you may want to deploy set of modules and not deploy other set of modules based of what a client has bought. That is the basic concept of module. Each module, by having a separate entrypoint, is a separately deployable unit of app. Multiple entrypoints in single module, doesnt make sense to me from technical as well business perspective.
sbidwai
A: 

It's usually better to only have one EntryPoint. Multiple EntryPoints in one module all start at the same time and that can sometimes do things you did not expect.

You have plenty of options in how to handle it separately: - Have 2 different compilations one for Admin and one for the Home application. - Use the history tokens to indicate that you want Admin or Home - Check a JS variable to show one or the other - Check the presence of a specific DIV id to show Admin or Home (RootPanel.get(id)) - Use URL parameters to indicate the application. - ... etc

David Nouls
A: 

Hi, I have a solution for this on my blog. You can download a sample maven project that has multiple entry points and uses url-rewriting. Take a look: http://zenoconsulting.wikidot.com/blog:16

Davis
+1  A: 

I also wanted to use multiple pages in a GWT toy app and I think I figured it out. It took some massaging of the deployment descriptor (myApp.gwt.xml), but here's what I did.

  • Made another class implementing EntryPoint and added some code that added to a div only in the new page.
  • Copied the original gwt.xml and changed two things:
    • The module-rename-to - I changed to "anothergwtapp"
    • The entry point specified the new class.
  • When I compile the project, there is another directory in the "war" folder called (wait for it...) "anothergwtapp". It contained the "anothergwtapp.nocache.js" that is the GWT magic.
  • Finally, I copied the orginal HTML page and replaced the "stockwatcher/stockwatcher.nocache.js" with "anothergwtapp/anothergwtapp.nocache.js" (yes, I'm very new - the tutorial is still on my machine)
    • I changed the new HTML to be a little different (new divs for the new entry point's onload to populate) and I added a simple href to the new page in the first page.

It worked. Just duplicate the gwt.xml and provide a new name for the module to go along with the new app page. I looked at some of the other links and I may have actually done what was described, but there were too many words and redirects and such (i.e. I didn't really read anything). I am using the latest GWT plugin for Galileo so maybe IJWs now.

Daver
A: 

Hi! Did you try this framework yet? http://gwtmultipage.org/ Claudius

Claudius