Difference between revisions of "Developing Portlets with GWT"
(→Configuring the portlet) |
(→Configuring the portlet) |
||
Line 118: | Line 118: | ||
</code> | </code> | ||
Write: | Write: | ||
− | + | ||
<!-- place portlet description here --> | <!-- place portlet description here --> | ||
<description xml:lang="en"><span style="color:(red);">Your Portlet description</span></description> | <description xml:lang="en"><span style="color:(red);">Your Portlet description</span></description> | ||
Line 128: | Line 128: | ||
<!-- place your portlet class name here --> | <!-- place your portlet class name here --> | ||
<portlet-class>org.gridlab.gridsphere.portlets.SamplePortlet</portlet-class> | <portlet-class>org.gridlab.gridsphere.portlets.SamplePortlet</portlet-class> | ||
− | |||
==Deploying the gwt-portlet== | ==Deploying the gwt-portlet== | ||
In order to deploy the gwt-portlet. | In order to deploy the gwt-portlet. |
Revision as of 15:22, 1 March 2007
How to write a portlet with the aim of GWT.
Contents
Pre-development Actions
Modifying Tomcat
- Replace $CATALINA_HOME/webapps/gridsphere/WEB-INF/CustomPortal/layouts/TemplateLayout.xml with the corresponding one found here.
- Include gwt.js and script.html files found here in $CATALINA_HOME/webapps/gridsphere/html directory.
Modifying Gridpshere Home
If you want you can also apply the respective changes to gridsphere's home directory. This can be useful if, for some reason, you want to redeploy gridsphere.
Installing GWT
- Download the latest version of GWT from here.
- Uzip the file.
- Set environmntal variable: GWT_HOME=<the name of the folder where you unpacked gwt files>
Creating a gwt-portlet
Creating a gwt project
In order to create a gwt project, you must execute:
>cd $GRIDPSHERE_HOME/projects >mkdir <module_dir_name> >cd <module_dir_name> >$GWT_HOME/projectCreator -eclipse MyProject >$GWT_HOME/applicationCreator -eclipse MyProject org.diligentproject.<whatever>.client.<ModuleName>
Now you can develop your gwt project as you wish by using eclipse!
FYI, there is a toolkit for eclipse that provides developers with a GUI so as to design their gwt modules.
However, it's not free. If you wish to see its demos, click here.
You can find useful information about the Google Web Toolkit on its official site: http://code.google.com/webtoolkit/
Creating a jsr 168 portlet
In oder to create an empty portlet project, you must execute:
>cd $GRIDPSHERE_HOME/ >ant new-project * insert: <Portlet's Title> * insert: <module_dir_name> --- This must be the same as in gwt project * insert: jsr
Now, if you refresh the eclipse project, you can see that the "portlet-files" are generated.
Creating the portlet class
- Create a class named: org.diligentproject.<whatever>.portlets.<portletClassName>
- Add the following content to the class:
// JSP folder name public static final String JSP_FOLDER = "/jsp"; // JSP file name to be rendered on the view mode public static final String VIEW_JSP = JSP_FOLDER + "/<a_name_for_the_jsp_page>.jsp"; public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException{ // ------------------------------------------------------------ // Note: The portlet is just diplaying a JSP for the AJAX Lab. // It does absolutely nothing else. // ------------------------------------------------------------ // Set the MIME type for the render response //response.setContentType(request.getResponseContentType()); // Invoke the JSP to render PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP); rd.include(request,response); }
Creating the jsp page
- Create a file in the webapp/jsp directory named: <a_name_for_the_jsp_page>.jsp.
- In this file you place the following content:
<%@ page contentType="text/html" %> <%@taglib uri="http://java.sun.com/portlet" prefix="portlet" %> <!-- --> <!-- The module reference below is the link --> <!-- between html and your Web Toolkit module --> <!-- --> <meta name='gwt:module' content='org.diligentproject.<whatever>.client.<ModuleName>'> <!-- --> <!-- This script is required bootstrap stuff. --> <!-- You can put it in the HEAD, but startup --> <!-- is slightly faster if you include it here. --> <!-- --> <div id="<a unique name for the DIV"> </div>
I should mention here that the org.diligentproject.<whatever>.client.<ModuleName> is the one you defined when you created the gwt application.
Additionally, the id for the div is good to be a name related to the portlet-name.
Configuring the portlet
- Modify the webapp/portlet.xml file as following:
Instead of:
<description xml:lang="en">This Portlet is a sample</description> <description xml:lang="de">Diese Portlet ist ein sample</description> <portlet-name>SamplePortlet</portlet-name> <display-name xml:lang="en">A sample Portlet</display-name> <display-name xml:lang="de">Ein sample Portlet</display-name> <portlet-class>org.gridlab.gridsphere.portlets.SamplePortlet</portlet-class>
Write:
<description xml:lang="en">Your Portlet description</description>
<description xml:lang="de">Diese Portlet ist ein sample</description>
<portlet-name>SamplePortlet</portlet-name>
<display-name xml:lang="en">A sample Portlet</display-name>
<display-name xml:lang="de">Ein sample Portlet</display-name>
<portlet-class>org.gridlab.gridsphere.portlets.SamplePortlet</portlet-class>
Deploying the gwt-portlet
In order to deploy the gwt-portlet.