JavaScript Error on Mouse Events with 2 Modules on 1 Page

9 views
Skip to first unread message

chi...@gmail.com

unread,
Oct 24, 2007, 10:50:32 PM10/24/07
to Google Web Toolkit
Hi Folks,

First of GWT is just awesome.. but I ran into a little issue when
using 2 modules one page. I opened up an issue report here:
http://code.google.com/p/google-web-toolkit/issues/detail?id=1804

And I'm hoping to see if anyone else has run into this. I have a main
gwt module that upon a user clicking a button it creates a div with an
ID that a second module looks for and puts it's content into it. The
second module just adds a few buttons and stuff inside that div and
all seems well so far. Problem is that any mouse events over the
buttons in the 2nd module will produce JavaScript errors.

I've attached simple project to the issue that shows this error in
action. Anybody run into this? Any clues what might be causing this
issue?

Thanks,
Hiram

Peter Blazejewicz

unread,
Oct 25, 2007, 4:24:00 PM10/25/07
to Google Web Toolkit
see comments by Fred Sauer:
http://code.google.com/p/google-web-toolkit/issues/detail?id=1804#c2
regards,
Peter

On Oct 25, 4:50 am, "hi...@hiramchirino.com" <chir...@gmail.com>
wrote:

Jason Essington

unread,
Oct 25, 2007, 5:59:02 PM10/25/07
to Google-We...@googlegroups.com
Hi Hiram

The issue is that the event system seems to get confused when you
have more than one module on a page.

The simple solution for you would be to create a third module with
only a gwt.xml file.

something like

com.foo.bar.CombinedModules.gwt.xml
<module>
<inherits name="com.foo.bar.Module1"/>
<inherits name="com.foo.bar.Module2"/>
</module>

Then just compile that third module
and only have a single <script> tag for CombinedModules on your host
page.

What this does is combine the two modules into a single monolithic
module. they still will act separately, and each module's onModuleLoad
() will be called, but, you will gain a few benefits ...

1) reduced byte count at page load
you'll only need one copy of code common to both modules. For
instance if module1 and module2 both use Button then you'd have two
separate button implementations (one in each module) however with the
monolithic module there will only be one.

2) reduced request count at page load
Each module is initially going to generate 3 requests (maybe only 2
on some browsers) so by combining the modules in this way, you reduce
the request count (and thus speed up page startup)

3) events will work as expected
Event handlers are registered as a method on the global window
object, so the last module to load will handle all of the events, and
if that last module doesn't actually generate events of its own, it
is likely that you'll get a call to null.nullMethod() which is
definitely a javascript error. By combining the modules, both modules
are running off of the single global event handler.

hope this helps

-jason

chi...@gmail.com

unread,
Oct 25, 2007, 6:03:24 PM10/25/07
to Google Web Toolkit
Actually I NEED 2 separate modules. The 2nd module will be hosted
external and loaded as a cross site script. If the 2nd module cannot
load, the page just has reduced functionality but still operates
normally.

Regards,
Hiram

chi...@gmail.com

unread,
Oct 25, 2007, 6:04:46 PM10/25/07
to Google Web Toolkit
Thanks for the links to the other issues!

On Oct 25, 4:24 pm, Peter Blazejewicz <peter.blazejew...@gmail.com>
wrote:

Jason Essington

unread,
Oct 25, 2007, 6:10:38 PM10/25/07
to Google-We...@googlegroups.com
In that case you'll want to have a look at the patches attatched to
issue 1788 (linked from 1546)

They attach the event handlers to the DOMImpl rather than to the
Window object, effectively creating separate event systems for each
module

give it a try and let me know if they work for you

-jason

Reply all
Reply to author
Forward
0 new messages