Tassos Bassoukos

Environmentaly friendly. Using 100% recycled electrons.

Using GWT modules in not-so-bright frameworks

I've recently had to use GWT to implement a module for a PostNuke installation. Two problems came up with that - first, the HTML head tag was in a static file somewhere, and I could not modify it and second, the URL that would call the module was not the URL for the files of the module.

To add a GWT module to a static page requires three things:

  1. A module specific element, which usually has a specific id attribute, where its contents will be replaced by the modules controls,
  2. A META tag in the HEAD of the page, specifying the modules that will be loaded,
  3. A SCRIPT tag linking to the gwt.js file.

Requirements (1) and (3) are easily met by modifying the actual HTML page, or in my case, emitting via PHP the HTML elements; however, requirement (2) is a bit harder to implement when one does not have access to the file that contains the HEAD element. Since we're doing AJAX anyway, a Javascript snippet will help us out a bit:

<script type="text/javascript">
   var headTag = document.getElementsByTagName('head')[0];
   var metaTag = document.createElement('meta');
   metaTag.setAttribute('name','gwt:module');
   metaTag.setAttribute('content','com.example.Module');
   headTag.appendChild(metaTag);
   headTag=null;
   metaTag=null;
</script>

Inserting that code before the tag for (3) will ensure that our module appears at least in the DOM. However, we aren't done yet, as the files for each module are resolved by GWT relative to the current location of the browser - which isn't that useful when your URL is something along the lines of "http://example.com/index.php?module=this&q=that" but your GWT modules reside in "/gwt-modules/example".

Googling around did not give any insight on the issue, so I delved a bit into the innards of GWT, and found an undocumented feature that allows one to rebind the base URL for a GWT module: simply use

<meta name="gwt:module" content="http://example.com/gwt-modules/example=com.example.Module" />

instead of

<meta name="gwt:module" content="com.example.Module" />

Obviously, this also allows for modules in different locations.

@ Tuesday, 10 October 2006, 12:57 in (Software) - 3 comments

Second Life has bigger GDP than 13 countries! >> << Infosystem 2006

Comments
  1. Comment by Dina on Thursday, 01 February 2007, 12:09
    I am adding in my jsp meta tag for loading gwt module, but gwt module don't load.
    Can you helpĀ  me?
  2. Comment by Tassos Bassoukos on Thursday, 01 February 2007, 12:54
    Dina, I'd love to, but I think that you might have more success looking at the GWT mailing lists. And don't forget to describe you problem and the solutions you've tried.
  3. Comment by inverse on Tuesday, 03 April 2007, 02:39
    Hello, thanks for your blog post, this is very nice to know. I tried to find a solution / suggest a feature on the GWT mailing list about this very issue, but it'd fallen onto deaf ears. Maybe I'm just not eloquent enough.

    Can you help me communicate this issue with the Google guys? The thread is here:
    http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/e4f76e0d45fd4255/acfb66b023f8928f?lnk=gst&q=modular&rnum=1#acfb66b023f8928f
Post a comment
Name:
Webpage:
Save this info.
Comment Text:
Trackback

The Trackback link for this post is here.