| | h3. Environment Setup |
| | |
| |  | GridSphere provides some mechanism to get started with portlet programming. In the GridSphere source directory you can use the command {{ant new-project}} to start a process at which end you will get a subdirectory containing some template files and a basic structure for your portlets. |
| | |
| | | GridSphere provides some mechanism to get started with portlet programming. In the GridSphere source directory you can use the command {{ant new-project}} to start a process at which end you will get a subdirectory containing some template files and a basic structure for your portlets. |
| | {noformat} |
| | ant new-project |
| | Buildfile: build.xml |
| | |
| | setenv: |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects |
| | [echo] Installing for Tomcat |
| | [echo] GridSphere Webserver is tomcat |
| | [echo] GridSphere will be deployed to /usr/local/apps/gs3/tomcat as the gridsphere web application |
| | |
| | new-project: |
| | |
| | new-project: |
| | [echo] Creating a New Portlet Project |
| | [input] Please enter a Project Title e.g. Cool Portlets |
| | GS Examples |
| | [input] Please enter a Project Name this will be used for your portlet web application and should be lowercase e.g. coolportlets |
| | gsexamples |
| | |
| | check-project-exists: |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples |
| | [copy] Copying 1 file to /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples |
| | [copy] Copying 1 file to /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/src |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/lib |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/WEB-INF |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/WEB-INF/classes |
| | [copy] Copying 1 file to /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/WEB-INF/classes |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/WEB-INF/persistence |
| | [copy] Copying 3 files to /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/WEB-INF |
| | [copy] Copying 1 file to /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/WEB-INF/persistence |
| | [copy] Copying 1 file to /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/WEB-INF |
| | [copy] Copying 1 file to /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/WEB-INF |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/html |
| | [mkdir] Created dir: /Users/wehrens/Projects/gs/svn/gridsphere/projects/gsexamples/webapp/jsp |
| | [echo] Creation of new portlet project GS Examples in projects/gsexamples is complete. |
| | [echo] Please edit src/ webapps/ and webapps/WEB-INF/{web.xml, PortletServices.xml} appropriately |
| | [echo] Please place portlets in src/**/portlets/ directory and service in src/**/services directory for proper compilation! |
| | |
| | BUILD SUCCESSFUL |
| | Total time: 15 seconds |
 |  | |
| | {noformat} |
 |  | This will create the project structure in the {{project}} directory of the GridSphere source directory. |
| | |
 |  | This will create the project structure in the {{project}} directory of the GridSphere source directory. |
| | |
| | h3. The structure |
 |  | |
| | {noformat} |
 |  | > ls -l projects/gsexamples/ |
| | total 48 |
| | -rw-r--r-- 1 wehrens wehrens 467 May 16 17:49 build.properties |
| | -rw-r--r-- 1 wehrens wehrens 17829 May 16 17:49 build.xml |
| | drwxr-xr-x 2 wehrens wehrens 68 May 16 17:49 lib |
| | drwxr-xr-x 2 wehrens wehrens 68 May 16 17:49 src |
| | drwxr-xr-x 5 wehrens wehrens 170 May 16 17:49 webapp |
| | | > ls -l projects/gsexamples/ |
| | total 48 |
| | -rw-r--r-- 1 wehrens wehrens 467 May 16 17:49 build.properties |
| | -rw-r--r-- 1 wehrens wehrens 17829 May 16 17:49 build.xml |
| | drwxr-xr-x 2 wehrens wehrens 68 May 16 17:49 lib |
| | drwxr-xr-x 2 wehrens wehrens 68 May 16 17:49 src |
| | drwxr-xr-x 5 wehrens wehrens 170 May 16 17:49 webapp |
| | {noformat} |
 |  | |
| | Change to the {{projects/gsexample}} directory and have a look at the files. |
| | |
| | *build.properties* |
 |  | This file was created during the previous process and contains your input as well as some other |
| | settings. |
| | |
| | |
| | used the | |
| | is | |
| | where GridSphere | |
| | Defines where the | |
| | Defines where the | |
| | the |
| | | any the |
| | | project.shared| | if this project provides any portlet services used by another portlet application, then the value |
| | | This file was created during the previous process and contains your input as well as some other |
| | settings. |
| | |
| | |
| | the be | |
| | is | |
| | where GridSphere | |
| | Defines where the | |
| | Defines where the | |
| | the |
| | | any the |
| | should be set to true | |
 |  | |
| | Once this file is generated you normally don't need to edit it (besides the optional project.version |
| | | Once this file is generated you normally don't need to edit it (besides the optional project.version |
| | property). |
| | |
| | *build.xml* |
 |  | This file normally does not need to be changed. It contains all targets for the default code structure to compile and deploy your code to GridSphere. |
| | | This file normally does not need to be changed. It contains all targets for the default code structure to compile and deploy your code to GridSphere. |
| | |
| | *lib* |
 |  | If you have 3rd party libraries to be used in your project you need to place them in that directory. |
| | | If you have 3rd party libraries to be used in your project you need to place them in that directory. |
| | |
| | *src* |
 |  | All your java based source code should go into that directory. One convention regarding the naming of the packagestructure must be followed if you want to use the the supplied build script. All portlets should be placed in a subdirectory named portlets (e.g. {{gsexamples/portlets}}). If you want to use the GridSphere portlet service model you have to place your service interfaces and implementations in a subdirectory named services (e.g. {{gsexamples/services}}). |
| | | All your java based source code should go into that directory. One convention regarding the naming of the packagestructure must be followed if you want to use the the supplied build script. All portlets should be placed in a subdirectory named portlets (e.g. {{gsexamples/portlets}}). If you want to use the GridSphere portlet service model you have to place your service interfaces and implementations in a subdirectory named services (e.g. {{gsexamples/services}}). |
| | |
| | *webapp* |
| | |
 |  | The webapp directory contains three directories. |
| | | The webapp directory contains three directories. |
| | {noformat} |
 |  | > ls -l webapp/ |
| | total 0 |
| | drwxr-xr-x 10 wehrens wehrens 340 May 18 13:12 WEB-INF |
| | drwxr-xr-x 2 wehrens wehrens 68 May 16 17:49 html |
| | drwxr-xr-x 2 wehrens wehrens 68 May 16 17:49 jsp |
| | | > ls -l webapp/ |
| | total 0 |
| | drwxr-xr-x 10 wehrens wehrens 340 May 18 13:12 WEB-INF |
| | drwxr-xr-x 2 wehrens wehrens 68 May 16 17:49 html |
| | drwxr-xr-x 2 wehrens wehrens 68 May 16 17:49 jsp |
| | {noformat} |
 |  | |
| | *webapp/WEB-INF* |
 |  | This is the normal WEB-INF directory of your portlet specification. Two files are needed to be there, {{web.xml}} and {{portlet.xml}}. Those are defined in JSR 168 and are required. The other files are GridSphere specific and ease the development and deployment of portlets to the GridSphere portal framework. |
| | |
| | | This is the normal WEB-INF directory of your portlet specification. Two files are needed to be there, {{web.xml}} and {{portlet.xml}}. Those are defined in JSR 168 and are required. The other files are GridSphere specific and ease the development and deployment of portlets to the GridSphere portal framework. |
| | {noformat} |
| | s -l webapp/WEB-INF/ |
| | total 24 |
| | -rw-r--r-- 1 wehrens wehrens 770 Jan 3 15:21 PortletServices.xml |
| | drwxr-xr-x 3 wehrens wehrens 102 Jan 3 15:21 classes |
| | drwxr-xr-x 3 wehrens wehrens 102 Jan 3 15:21 persistence |
| | -rw-r--r-- 1 wehrens wehrens 3857 Jan 3 15:21 portlet.xml |
| | -rw-r--r-- 1 wehrens wehrens 2112 Jan 3 15:21 web.xml |
| | {noformat} |
| | |
| | h3. Programming |
 |  | Now that we have our project setup we can go ahead and develop some portlets. |
| | |
 |  | h5. Hello World |
| | | Now that we have our project setup we can go ahead and develop some portlets. |
| | |
 |  | First we will create a simple Hello World Portlet using JSR 168 standard methods. Create a subdirectory {{src/org/gridsphere/gsexamples/portlets}} and create the {{File HelloWorld.java}}. |
| | | h5. Hello World |
| | |
 |  | First we will create a simple Hello World Portlet using JSR 168 standard methods. Create a subdirectory {{src/org/gridsphere/gsexamples/portlets}} and create the {{File HelloWorld.java}}. |
| | {code:title=HelloWorld.java} |
| | package org.gridsphere.gsexamples.portlets; |
| | |
| | import javax.portlet.GenericPortlet; |
| | import javax.portlet.RenderRequest; |
| | import javax.portlet.RenderResponse; |
| | import javax.portlet.PortletException; |
| | import java.io.PrintWriter; |
| | import java.io.IOException; |
| | |
| | /** |
| | * a simple HelloWorld Portlet |
| | */ |
| | public class HelloWorld extends GenericPortlet { |
| | |
| | public void doView(RenderRequest request, RenderResponse response) |
| | throws PortletException, IOException { |
| | response.setContentType("text/html"); |
| | PrintWriter out = response.getWriter(); |
| | out.println("<h1>Hello World</h1>"); |
| | } |
| | |
| | } |
| | {code} |
 |  | |
| | Now we need to modify {{portlet.xml}} so that GridSphere recognizes the portlet (or any other JSR compliant portlet container). We do already have a template {{portlet.xml}} in the {{webapp/WEB-INF}} directory deployed. Please replace the current portlet section with the follwing entry: |
| | |
| | | Now we need to modify {{portlet.xml}} so that GridSphere recognizes the portlet (or any other JSR compliant portlet container). We do already have a template {{portlet.xml}} in the {{webapp/WEB-INF}} directory deployed. Please replace the current portlet section with the follwing entry: |
| | {code:title=portlet.xml|language=xml} |
| | <portlet> |
| | <description xml:lang="en"> |
| | The classic Hello World example |
| | </description> |
| | <portlet-name>HelloPortlet</portlet-name> |
| | <display-name xml:lang="en">Hello World</display-name> |
| | <portlet-class> |
| | org.gridsphere.gsexamples.portlets.HelloWorld |
| | </portlet-class> |
| | <expiration-cache>60</expiration-cache> |
| | <supports> |
| | <mime-type>text/html</mime-type> |
| | <portlet-mode>edit</portlet-mode> |
| | <portlet-mode>help</portlet-mode> |
| | </supports> |
| | <supported-locale>en</supported-locale> |
| | <portlet-info> |
| | <title>Hello World</title> |
| | <short-title>Hello World</short-title> |
| | <keywords>hello</keywords> |
| | </portlet-info> |
| | </portlet> |
| | {code} |
 |  | This defines the HelloWorld portlet with the portlet name of HelloPortlet (line 5), the portlet class beeing our HelloWorld example (line 8), a cachetime of 60 seconds (line 10), an edit (line13) and help (line 14) mode. Furthermore some information about the portlet is provided (line 17-21). |
| | |
 |  | This defines the HelloWorld portlet with the portlet name of HelloPortlet (line 5), the portlet class beeing our HelloWorld example (line 8), a cachetime of 60 seconds (line 10), an edit (line13) and help (line 14) mode. Furthermore some information about the portlet is provided (line 17-21). |
| | |
| | Now we are ready to compile and deploy the Hello World Portlet. |
 |  | |
| | {noformat} |
 |  | > ant install |
| | Buildfile: build.xml |
| | setenv: |
| | [mkdir] Created dir: gridsphere/projects/gsexamples/build |
| | ... |
| | BUILD SUCCESSFUL |
| | Total time: 7 seconds |
| | | > ant install |
| | Buildfile: build.xml |
| | setenv: |
| | [mkdir] Created dir: gridsphere/projects/gsexamples/build |
| | ... |
| | BUILD SUCCESSFUL |
| | Total time: 7 seconds |
| | {noformat} |
 |  | After the deployment of the portlet to the portal and configuring GridSphere to display it (go to Layout in the upper right corner and add it the desired layout), you will see your HelloWorld portlet. |
| | |
 |  | After the deployment of the portlet to the portal and configuring GridSphere to display it, you will see your HelloWorld portlet. |
| | |
| | !HelloWorld.png! |
| | |
| | h3. Source code |
| | |
| | Get the full source code for this example: [^gsexamples.zip]. Unzip this into the projects directory (you maybe have to create this directory first). |
 | | |
| | |
| | |
| | |
| | |