Portlets and GWT look nice together. At first sight.
There is one problem in their cooperation: we can't use multiple instances of same GWT modules in one html page, so we can't build normal portlet.
For example, I have simple GWT module with this entry point:
public class XLam implements EntryPoint {
...
public void onModuleLoad()
{
RootPanel.get("unique_html_element_id").add(somewidget);
}
}
And I would like to add this GWT module into my portlet. For this case I write code:
public class XLamPortlet extends GenericPortlet
{
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, PortletSecurityException, IOException
{
...
writer.println("<script language='javascript' src='" + renderRequest.getContextPath() + "/xqx.web.xlam.XLam.nocache.js'></script>");
writer.println("<div id='unique_html_element_id'></div>");
...
}
}
When I try to place two same portlets into one page I get collision between GWT instances, of course.
I think, that should be way to resolve this problem and I'm trying to find it.
Has someone any solution for this?Today I've researched JavaScript, which generated by GWT compiler.
I found some ways how to resolve this problem.
It is possible to change some parts of the *.js compiled code, e.g.:.
Rewrite in *.cache.html
..
function wq(a)
{
hh(pi('unique_html_element_id'), a.b);
hh(pi($wnd.unique_html_element_id), a.b);
a.c = lq(new kq(), a);
id(a.c, 1000);
}
...
Define variables 'on the fly' in *.nocache.js
...
var unique_html_element_id='unique_html_element_id';
...
Or, maybe, rewrite or append additional parameters to some functions like this:
function gwtOnLoad(b, d, c)
But all these are dead-end ways :-(
I think, Google may create useful mechanism for this.
How? I mean, via special parameter in EntryPoint.onModuleLoad() function.
GWT Team, it is really necessary for many web developers!