dynamically load GWT module

422 views
Skip to first unread message

monkey01

unread,
May 6, 2010, 2:57:31 AM5/6/10
to Google Web Toolkit
I want to dynamically load another GWT module in one initial GWT
module, but it does not work. Here's what I tried.

1. I tried to static load both module in the hosting page with no
problem.

========================
.....
<div id="gwt-module1"></div>
<div id='gwt-module2'></div>
.....
<script scr="/a/...Module1.nocache.js" />
<script scr="/b/...Module2.nocache.js" />
.....
==============================

2. Then I tried to load module2 dynamically, it won't work. When I
click on the button, the whole page is wiped out, and the current page
comes to endless loading/waiting status.
===================================
<div id="gwt-module1"></div>
<div id='gwt-module2'></div>

<script scr="/a/...Module1.nocache.js" />
<script type="text/javascript" language="javascript">
function loadModule2(){
var head = document.getElementsByTagName('head')[0];
script = document.createElement('script');
script.id = 'loadShellAppScript';
script.type = 'text/javascript';
script.src = /b/...Module2.nocache.js';
head.appendChild(script);
}

</script>

<button onclick='loadModule2();'>click me</button>

=================================

Any idea? Why a static js src works but dynamic load fails? What's the
best approach to dynamically load another module? Do I have to create
an iframe in order to load another gwt module? Any one tried that?

All the files are serving at one server, and both modules work fine in
their own hosting page.

Thanks.

Yunfeng Hou

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

kozura

unread,
May 6, 2010, 5:05:38 PM5/6/10
to Google Web Toolkit
Not knowing your reasoning for wanting to load two modules in a page,
multiple modules can work as:

- Separate pages, so loading second module completely takes over from
the first
- Within an iframe, same idea but can be loaded from within the first
page
- Code splitting, probably the best way to solve most reasons for
wanting separate "modules" to work together

If you mention why you want to use separate modules, can probably help
you decide which way to go.

lineman78

unread,
May 6, 2010, 7:40:47 PM5/6/10
to Google Web Toolkit
I have been looking for a solution to this problem for over a year and
every time I get close they change the default linker and break any
workaround I have found. I still advocate that there is a need for
this to be supported by a GWT linker, even if it isn't the default
one, but I did find one solution that you may solves the problem. The
idea is that when you install such a module, a reference is kept on
the server side and the index.jsp is populated with the script tags
for all installed modules. Each sub module must contain a class that
extends an abstract sub module. The abstract sub module must use a
method similar to GWTExporter to expose the root element of the module
and a way to make calls between the modules. Also, I put a layer
between the abstract methods to do these things and the native methods
in order to do RunAsync and limit loading. You also will have to make
a common sub module entry point that calls GWT.create on your abstract
sub module and in the implementing module you will have to use
deferred binding to get it to work. You will also have to call
GWT.create on your exporter class here in order to inject it's native
methods. I'm sorry I cannot post any source code and this is as far I
can go in explaining it, but you should end up with 3 modules + any
sub modules...

/GWTPluggableCore.gwt.xml
/GWTPluggableCommon.gwt.xml
/core/CoreEntryPoint.java (extends EntryPoint)
/common/AbstractSubModule.java (

/submod/SubModuleCommon.gwt.xml (entry-point SubModuleEntryPoint,
inherits GWTPluggableCommon)
/submod/SubModule1.gwt.xml (replaces AbstractSubModule with SubModule,
inherits SubModuleCommon)
/submod/common/SubModuleEntryPoint.java (extends EntryPoint)
/submod/submod1/SubModule.java (extends AbstractSubModule)

Here is a thread from a little over a month ago where I asked the same
question:
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/dcf33b6ba98aaaf/cbc4420cca462639?hl=en&lnk=gst

Tiago A. Silva

unread,
May 6, 2010, 5:08:10 PM5/6/10
to google-we...@googlegroups.com
Pessoal, Desenvolvo projetos em GWT a mais ou menos 1 ano e meio, gostaria de saber se alguém necessita de alguma ajuda, ou até mesmo me indicar para trabalhar com gwt.

Abraços.

2010/5/6 kozura <koz...@gmail.com>
Reply all
Reply to author
Forward
0 new messages