You are on page 1of 22

Hands On

Installing and Programming


Gridsphere 2.1.2
Oliver Wehrens
(oliver.wehrens@aei.mpg.de)

Albert Einstein Institut (MPG)


Requirements
You will need the following software packages on
you local machine
Java > 1.4.x (java.sun.com)
Apache Ant > 1.6 (ant.apache.org)
Apache Tomcat > 5.0.x (tomcat.apache.org)
Knowledge in Java programming
Knowledge in Servlet programming
It helps to have a look at the JSR 168
specification (http://jcp.org/en/jsr/detail?id=168)
or read articles on javaworld.com (http://
www.javaworld.com/javaworld/jw-08-2003/
jw-0801-portlet.html) or sun.com (http://
developers.sun.com/prodtech/portalserver/
reference/techart/jsr168/)
Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)
Requirements (II)
For programming part a good Java IDE (please
don’t use vi for real programming)
NetBeans (www.netbeans.org)
Eclipse (www.eclipse.org)
IntelliJ Idea (www.jetbrains.org) commercial

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Getting GridSphere
GridSphere is available from http://
www.gridsphere.org/gridsphere/gridsphere?
cid=download
Download GridSphere 2.1.2 (we will refer to that
directory from now on as GRIDSPHERE_HOME)
Unzip/Untar it
$CATALINA_HOME needs to be set to the root
directory of tomcat
ANT_HOME needs to be set to the root directory
of ant
export ANT_HOME=

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Installing
cd gridsphere
ant install
To enable deploying portlets in a running
GridSphere please modify the $CATALINA_HOME/
conf/tomcat-users.xml file
$CATALINA_HOME/bin/startup.sh

<?xml version='1.0' encoding='utf-8'?>


<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="gridsphere" password="gridsphere" roles="manager,admin"/>
</tomcat-users>

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Setup GridSphere
Fill out the GridSphere setup screen

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Running GridSphere

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Programming
Stop tomcat ($CATALINA_HOME/bin/
shutdown.sh)
We will create a ‘Hello World’ Example
Steps involved:
Create the templates
Create the jsp, the portlet code
Modify the descriptor files
Deploy to GridSphere
Change the Code
Redeploy to GridSphere
We going to write a classic HelloWorld with some
Action
All files can be found at http://www.aei.mpg.de/
~wehrens/dgrid/handsonworkshop20060301/
<filename> Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)
Creating template files
GridSphere provides a mechanism to create
template files for your project
It is not required to use but it provides some help
In GRIDSPHERE_HOME run ‘ant new-project’
You will be asked for a project title, enter Hello World
You will be asked for a project name, this will be used for
the webapplication name, enter helloworld (this will be
used as directory name for your project)
You will be asked whether you want this to be a GS or
JSR portletwebapp, enter jsr
All templatefiles are now created in
GRIDSPHERE_HOME/project/helloworld
If you made a mistake simply erase the
GRIDSPHERE_HOME/project/helloworld directory
and start over again
Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)
Creating the JSP
JSP’s are stored in webapp/jsp subdirectory of
your just created helloworld project
Create a subdirectory helloworld in the jsp
directory
Create a jsp file uihelloworld.jsp there
<%@ taglib uri="/portletUI" prefix="ui" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<portlet:defineObjects/>

<p>

<ui:form>
Hello, <ui:text beanId="nameTB"/> !
<ui:textfield size="20" beanId="nameTF"/>
<ui:actionsubmit action="showName" value="Say Hello!"/>
</ui:form>

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Creating the portlet
Create a directory src/org/gridlab/
gridsphere/jsrtutorial/portlets/helloworld
Create the following portletcode in
UiHelloWorld.java:

package org.gridlab.gridsphere.jsrtutorial.portlets.helloworld;

import org.gridlab.gridsphere.provider.portletui.beans.CheckBoxBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextFieldBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextBean;
import org.gridlab.gridsphere.provider.event.jsr.RenderFormEvent;
import org.gridlab.gridsphere.provider.event.jsr.ActionFormEvent;
import org.gridlab.gridsphere.provider.portlet.jsr.ActionPortlet;

import javax.servlet.UnavailableException;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


UiHelloWorld.java
public class UiHelloWorld extends ActionPortlet {

private static final String DISPLAY_PAGE = "helloworld/uihelloworld.jsp";

public void init(PortletConfig config) throws PortletException {


super.init(config);
DEFAULT_VIEW_PAGE = "prepare";
}

public void showName(ActionFormEvent event) throws PortletException {


TextFieldBean name = event.getTextFieldBean("nameTF");
event.getActionResponse().setRenderParameter("helloname", name.getValue());
/*CheckBoxBean bold = event.getCheckBoxBean("bold");
if (bold.isSelected()) {
TextBean helloname = event.getTextBean("nameTB");
helloname.setStyle(TextBean.MSG_BOLD);
} */
setNextState(event.getActionRequest(), DEFAULT_VIEW_PAGE);
}

public void prepare(RenderFormEvent event) throws PortletException {


String name = event.getRenderRequest().getParameter("helloname");
TextBean helloname = event.getTextBean("nameTB");
if (name == null) {
helloname.setValue("unknown");
} else {
helloname.setValue(name);
} Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)
setNextState(event.getRenderRequest(), DISPLAY_PAGE);
}
}
Deployment descriptors
All files are located in GRIDSPHERE_HOME/webapp/
WEB-INF
We need to edit a couple of deployment
descriptor files
portlet.xml - JSR 168 standard, describing the portlet
layout.xml - GridSphere file, describing the layout of the
portlet within a page
group.xml - GridSphere file, Describing a collection of
portlets
More files are needed but are autogenerated and
need not to be modified for this example
web.xml - Standard web.xml descriptor
gridsphere-portlet.xml - GridSphere specific
PortletServices.xml - For use with GridSphere Portlet
Services
Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)
portlet.xml
Edit the <portlet/> section of the portlet.xml
...
<portlet>
<description xml:lang="en">
The classic Hello World example using UI tag library
</description>
<portlet-name>UiHelloPortlet</portlet-name>
<display-name xml:lang="en">UI Hello World</display-name>
<portlet-class>
org.gridlab.gridsphere.jsrtutorial.portlets.helloworld.UiHelloWorld
</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>UI Hello World</title>
<short-title>UI Hello World</short-title>
<keywords>hello</keywords>
</portlet-info>
</portlet>

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


layout.xml

<portlet-tabbed-pane>
<portlet-tab label="Hello World">
<title lang="en">Hello</title>
<portlet-tabbed-pane style="sub-menu">
<portlet-tab label="helloworld">
<title lang="en">UI Hello</title>
<table-layout>
<row-layout>
<column-layout>
<portlet-frame label="helloworldportlet">
<portlet-class>
org.gridlab.gridsphere.jsrtutorial.portlets.helloworld.UiHelloWorld
</portlet-class>
</portlet-frame>
</column-layout>
</row-layout>
</table-layout>
</portlet-tab>
</portlet-tabbed-pane>
</portlet-tab>
</portlet-tabbed-pane>

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


group.xml

<portlet-group>
<group-name>HelloWorld</group-name>
<group-description>UI Hello World Example</group-description>
<group-visibility>PUBLIC</group-visibility>
<portlet-role-info>
<portlet-class>
org.gridlab.gridsphere.jsrtutorial.portlets.helloworld.UiHelloWorld
</portlet-class>
<required-role>USER</required-role>
</portlet-role-info>
</portlet-group>

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Deployment
Use ‘ant install’ to deploy this portlet to
GridSphere
Start GridSphere
Subscribe to the Hello World group in the Profile
Manager

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Deployed portlet!
Click on the ‘Hello’ tab
Enter your name!

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Change the portlet
change src/org/gridlab/gridsphere/
jsrtutorial/portlets/helloworld/
UiHelloWorld.java and remove the comments /
* */

...
public void showName(ActionFormEvent event) throws PortletException {
TextFieldBean name = event.getTextFieldBean("nameTF");
event.getActionResponse().setRenderParameter("helloname", name.getValue());
/*CheckBoxBean bold = event.getCheckBoxBean("bold");
if (bold.isSelected()) {
TextBean helloname = event.getTextBean("nameTB");
helloname.setStyle(TextBean.MSG_BOLD);
} */
setNextState(event.getActionRequest(), DEFAULT_VIEW_PAGE);
}
...

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Change the jsp
edit jsp/helloworld/uihelloworld.jsp to
include a checkbox that will output the name in
bold

<%@ taglib uri="/portletUI" prefix="ui" %>


<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<portlet:defineObjects/>

<ui:form>
Hello, <ui:text beanId="nameTB"/> !
bold: <ui:checkbox beanId="bold"/>
<ui:textfield size="20" beanId="nameTF"/>
<ui:actionsubmit action="showName" value="Say Hello!"/>
</ui:form>

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Redeploy Portlet
ant install
In GridSphere reload the Hello World portlet app

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)


Bold portlet

Team GridSphere, Oliver Wehrens (oliver.wehrens@aei.mpg.de)

You might also like