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:
- A module specific element, which usually has a specific id attribute, where its contents will be replaced by the modules controls,
- A META tag in the HEAD of the page, specifying the modules that will be loaded,
- 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.



Comments