tags:

views:

1251

answers:

2

We are developing a set of portlets for Liferay. Currently we use JSPs, so we are able to use the tag for the DIV and element IDs so that they are unique on the page, even if multiple instances of the same portlet appear on the page; for example:

<div id='<portlet:namespace/>div'>  
<form>
    Enter your name here: <input type='text' id='<portlet:namespace/>name'/>  
</form>  
</div>

Now we'd like to try building the portlets with GWT instead of JSP. Any examples I find of GWT portlets (of which there are only a couple) don't solve the "how do I assign unique IDs to the div and elements" problem, since GWT seems to be pre-compiled into Javascript before the IDs are ever generated. Any idea on how to incorporate the portlet's namespace into the div/element IDs?

A: 

GWT contains an setId() method on the Element class which you can use.

If you're using Widgets, you can call widget.getElement().setId(...)

A: 

Here's the best link I found: http://xantorohara.blogspot.com/2007/07/portlets-and-gwt.html

I solved it by using an unique id for each GWT-based portlet, at the root container level. Besides this, I implemented the Command pattern and had a Command dispatcher based on GWT's history support that would dispatch appropriate actions to a portlet without interfering with other portlets.

Since liferay supports jsr 286, you can arrange a GWT ajax call that would return the portlet id and use that id to distinguish between different portlets.

Miguel Ping