
Build a GWT Portlet
Table of Contents [-]
Introduction #
There are two possibilities for integrating GWT into the portlet: using a div container, and using an iFrame.
Using a div-Container #
1. Create a simple JSP Portlet by using the Liferay Plugins SDK. In the subfolder portlets of the SDK run:
ant -Dportlet.name=helloGWT-portlet -Dportlet.display.name="Hello GWT" create
2. Open the view.jsp (/plugin/portlets/helloGWT-portlet/docroot) of the JSP portlet and add this part:
<script src="<%=request.getContextPath()%>/html/com.google.gwt.sample.hello.Hello.nocache.js"></script><div id="uniqueID"></div>
3. As an example use the Hello example application from the GWT bundle. Edit the class Hello of the GWT Hello example to:
RootPanel.get("uniqueID").add(b);
4. Compile the GWT application
5. Copy all the files from the folder
gwt-linux-1.5.0/samples/Hello/www/com.google.gwt.sample.hello.Hello to your JSP portlet
into
helloGWT-portlet/docroot/html
6. Run ant deploy and test your portlet in your Liferay Portal
Using an IFrame #
1. Create a simple JSP Portlet by using the Liferay Plugins SDK. In the subfolder portlets of the SDK run:
ant -Dportlet.name=helloGWT-portlet -Dportlet.display.name="Hello GWT" create
2. As an example use the Hello example application from the GWT bundle. Copy all the files from the folder
gwt-linux-1.5.0/samples/Hello/www/com.google.gwt.sample.hello.Hello to your JSP portlet
into
helloGWT-portlet/docroot/html
3. Open the view.jsp (/plugin/portlets/helloGWT-portlet/docroot) of the JSP portlet and add this part:
<iframe src="<%=request.getContextPath()%>/html/Hello.html" frameborder="0"></iframe>
4. Run ant deploy and test your portlet in your Liferay Portal
Exceptions & Handling #
This is observed in Liferay 5.2 , when we deploy the portlet and try to add it to our application then the widget from GWT is not visible. On subsequent refresh the widget becomes visible. This makes the following corrective steps
- Ensure cache is cleared , the best way is to have the JSP do it rather than depending on the browser
- Clear browser cache manually.
It must be remembered that GWT finally compiles to Javascript and hence caching might be a problem for the latest widgets to display.