Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Introduction to Portlet
Programming with JSR-168
Noel J. Bergman
DevTech
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 1
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Session Overview
Portals are a hot growth area, but prior to JSR-168, we lacked a
standard API for Portlet Development. This session will introduce
the unique characteristics of Portals, the Portlets of which they are
built, and the JSR-168 specification that enables portability
between Portlet containers.
Topics will include aggregation, request processing, URIs, modes
and states, dispatching, preferences, selected vendor extensions
and more.
Although this session is offered as an introduction to Portals and
JSR-168, prerequisites include understanding of XML, HTML,
Servlets and JavaServer Pages.
PLEASE ASK QUESTIONS!
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 2
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Session Prerequisites
You will want a good understanding of
Servlets and JavaServer Pages.
You will want an understanding of XML and
HTML.
In order to work with the technology
covered during the session, you will need a
JSR-168 compliant Portal server, such as one
of the ones well use for demonstrations.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 3
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Portal Demonstrations
Lets look at some sample portals.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 4
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
What Is a Portal?
Portals are distinguished by a number of
characteristics. The two most often
observed by users are:
Aggregation
Personalization
These characteristics have a major impact
on the programming model, and how it
differs from a non-portal web site.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 5
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Aggregation
Aggregation refers to taking content from
multiple, independent, delivery channels,
and providing a unified user experience.
A Portal page will often contain multiple
portlets, each rendering content from a
separate source.
Aggregation is outside of the scope of JSR168. Many Portal engines manage pages
and aggregation differently.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 6
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Personalization
Personalization refers to allowing each user
to customize their portal experience.
Different portal engines will provide for
differing levels of personalization.
JSR-168 includes a notion of Portlet
Preferences, which a developer can use to
allow a user to customize how the portlet
will perform for that specific user.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 7
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
What Is JSR-168?
The numeric designation for the JCPs first local
Portlet Specification.
Remote portlet technology is defined by the WSRP
specification.
Extends Servlet Specification 2.3 with new Portlet
concepts.
Defines the standard contract between the Portlet
container and Portlet components.
JSR-168 does not define Portal behaviors, such as how
pages are laid out, how aggregation works, how
administration is performed, etc.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 8
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Why JSR-168?
Prior to JSR-168, we had many different
Portlet APIs. The lack of standards
fragmented the solution space, creating
issues for customers and ISVs.
This session focuses on Portlets and related semantics as defined by
JSR-168. We will not be discussing the original Jetspeed API, the IBM
Portlet API (a Jetspeed fork), the uPortal API, or other, non-standard,
Portlet APIs, which may offer more or less differing semantics.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 9
Portlet-based Applications vs
Servlet-based Applications
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Installing a Portlet Application provides
capability, not content.
Portlets from multiple applications can be
aggregated on the same page.
More administration with Portlets and Portals
than with traditional web applications.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 10
Some of the Portal Servers
That Support JSR-168
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Open Source
Pluto (http://portals.apache.org/pluto)
Jetspeed-2 (http://portals.apache.org/jetspeed-2)
GridSphere (http://www.gridsphere.org)
uPortal (http://www.uPortal.org)
Liferay (http://www.liferay.com)
Commercial
WebSphere Portal Server (http://www.ibm.com/software/genservers/portal)
WebLogic Portal Server (www.bea.com/products/weblogic/portal)
Oracle Portal Server (http://www.oracle.com/technology/products/ias/portal)
Plumtree Corporate Portal (http://www.plumtree.com/products/platform)
JSR-168 is not supported by all versions of each portal server
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 11
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
What Is a Portlet?
A new type of Web Component, cousin to
the Servlet.
Provides the interface to content. In MVC
terms:
Portlet class Controller
Portlets JSP View
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 12
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Portlets Differ from Servlets
Two phase request processing
Persistent render parameters
Portlet render as markup fragments
Special URLs to access a Portlet
Portlet Modes
Portlet Window States
Portlet Preferences
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 13
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Model/View/Controller Pattern
Model
Abstract interface
No user interaction
No presentation
View
Acquires Model data and renders it
Can be replaced, independent of the Model
Controller
Receives input events
Provides the means to effect change on the Model
Orchestrates interaction between Model and View
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 14
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
MVC and Portlets
The Portlet's primary role is as the Controller.
Receives events from the container
Process actions
Render content
Portlets typically dispatch to the View (usually a
JSP page).
As the Controller, Portlets orchestrate interaction
with the Model and moving content to the View.
The Model can be anything: POJO, EJB, Web
Service, etc.
A Portal is intended to provide an aggregated UI to
models, not to necessarily contain those models.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 15
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Portlet URLs
Portlets do not have a directly exposed endpoint exposed to the browser. Special URLs
are encoded that tell the container what to
do.
JSR-168 specifies two types of URLs:
ActionURL invokes a portlets action handling.
RenderURL invokes a portlets render behavior.
We will cover these concepts in more detail
later.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 16
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Portlet Modes
Portlets have modes, which are a view-related convenience.
JSR-168 specifies standard modes, which are typically used
as:
View application interaction, but not as the name might imply
read only.
Edit present a screen for editing user preferences
Help provide help
JSR-168 also supports the idea of custom modes.
Unlike, for example, modes within the IBM Portlet API,
modes in JSR-168 are advisory.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 17
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Window State
Portlets have a Window State, which tells the
container how much space to provide. The
standard Window States are:
Normal shares space on the page with other portlets.
Minimized minimal space, e.g., only the titlebar might
be shown.
Maximized receives the entire space on the page that
is available to a portlet.
JSR-168 also provides for custom Window States,
e.g., a half window state, requesting half of the
available screen space.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 18
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Deployment Descriptor
portlet.xml
Defines:
Portlets
Name
Display Name
Portlet Class
Initialization Parameters
Resource Bundle
Preferences Validator
Caching
Markups and Modes supported
Locales supported
Preferences
Security Role References
Custom Modes
Custom Window States
Security Constraints
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 19
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The javax.Portlet Package
ActionRequest
ActionResponse
GenericPortlet
PortalContext
Portlet
PortletConfig
PortletContext
PortletException
PortletMode
PortletModeException
PortletPreferences
PortletRequest
PortletRequestDispatcher
Legend:
Class
Noel Bergman Introduction to Portlet Programming with JSR-168
PortletResponse
PortletSecurityException
PortletSession
PortletSessionUtil
PortletURL
PreferencesValidator
ReadOnlyException
RenderRequest
RenderResponse
UnavailableException
ValidatorException
WindowState
WindowStateException
Interface
Page 20
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The Portlet Interface
Minimalist interface
public interface Portlet {
void init(PortletConfig);
void processAction(ActionRequest, ActionResponse);
void render(RenderRequest, RenderResponse);
void destroy();
}
Thats it!
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 21
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The GenericPortlet Class
public abstract class GenericPortlet implements Portlet, PortletConfig
{
public void init() throws PortletException
public PortletConfig getPortletConfig()
protected java.lang.String getTitle(RenderRequest request)
protected void doDispatch(RenderRequest request, RenderResponse response)
protected void doView(RenderRequest request, RenderResponse response)
protected void doEdit(RenderRequest request, RenderResponse response)
protected void doHelp(RenderRequest request, RenderResponse response)
... inherited methods ...
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 22
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The GenericPortlet Class
Portlets will normally extend this class,
rather than implement Portlet directly.
Will typically override:
void processAction(ActionRequest, ActionResponse);
void doMode(RenderRequest, RenderResponse);
Might override:
protected java.lang.String getTitle(RenderRequest request)
To implement a custom mode, override:
void doDispatch(RenderRequest, RenderResponse);
void doMode(RenderRequest, RenderResponse);
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 23
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Hello World, Portlet-Style
package com.devtech.com.portlets;
import javax.portlet.*
public class HelloPortlet extends GenericPortlet
{
protected void doView(RenderRequest req, RenderResponse res)
{
res.setContentType(text/html);
res.getWriter().writeln(<P>Hello World</P>);
}
}
We really should not be using the Writer; should be using a dispatcher with a JSP page.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 24
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Hello World v2, Portlet-Style
package com.devtech.com.portlets;
import javax.portlet.*
public class HelloPortlet extends GenericPortlet
{
public void processAction(ActionRequest req, ActionResponse res)
{
String who = req.getParameter(greet);
if (who == null) who = World;
res.setRenderParameter(msg, Hello + who);
}
protected void doView(RenderRequest req, RenderResponse res)
{
res.setContentType(text/html);
res.getWriter().writeln(<P> + req.getParameter(msg) + </P>);
}
}
This portlet would NOT work as-is. We havent provided a means to access the action.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 25
Two-phase Request
Processing
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Action Phase
Initiated by an ActionURL.
Allows a redirect relative to the Portlet Application.
The only time you can access the request body.
Provides Render Parameters for the Render Phase.
Render Phase
Idempotent
Replayable Render Parameters
Set by the portlet during action processing, or attached to a
RenderURL.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 26
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Action Phase
void processAction(ActionRequest, ActionResponse);
ActionRequest provides access to the
HTTP request.
ActionResponse does not generate
output. It is used to set the parameters that
will be available during the render phase.
Preferences can be stored only during this
phase.
See also: ActionRequest/ActionResponse
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 27
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Render Phase
void render(RenderRequest, RenderResponse);
Generally implemented by doMode()
methods.
RenderRequest does not provide access to
parameters provided by an ActionURL or
form, only to parameters explicitly set by a
RenderURL or by methods on
ActionResponse.
See also: RenderRequest/RenderResponse
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 28
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The PortletConfig Interface
public interface PortletConfig
{
public String getPortletName();
public PortletContext getPortletContext();
public ResourceBundle getResourceBundle(Locale locale);
public String getInitParameter(String name);
public Enumeration getInitParameterNames();
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 29
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The PortletConfig Interface
Allows a Portlet to access its
PortletContext, resource bundle
associated with the Portlet, and initialization
parameters.
Initialization parameters are defined by
<init-param> tags in portlet.xml,
similar to those for servlets that are in
web.xml.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 30
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The PortletContext Interface
public interface PortletContext
{
public String getServerInfo();
public PortletRequestDispatcher getRequestDispatcher(String path);
public PortletRequestDispatcher getNamedDispatcher(String name);
public InputStream getResourceAsStream (String path);
public int getMajorVersion();
public int getMinorVersion();
public String getMimeType(String file);
public String getRealPath(String path);
public Set getResourcePaths(String path);
public URL getResource(String path) throws MalformedURLException;
public Object getAttribute(String name);
public Enumeration getAttributeNames();
public String getInitParameter(String name);
public Enumeration getInitParameterNames();
public void log(String msg);
public void log(String message,Throwable throwable);
public void removeAttribute(String name);
public void setAttribute(String name,Object object);
public String getPortletContextName();
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 31
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The PortletContext Interface
The Portlets view of the container.
Provides access to context parameters,
defined in web.xml, and context scoped
attributes.
Most methods provide the same functionality
as the similarly named methods of the
ServletContext.
The get[Request|Named]Dispatcher
method is used to get a dispatcher for other
dynamic resources within this application.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 32
The PortletRequest
Interface
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
public interface PortletRequest
public Principal getUserPrincipal();
public boolean isUserInRole(String role);
public static final String USER_INFO
public Object getAttribute(String name);
public static final String BASIC_AUTH
public Enumeration getAttributeNames();
public static final String FORM_AUTH
public String getParameter(String name);
public static final String CLIENT_CERT_AUTH
public Enumeration getParameterNames();
public static final String DIGEST_AUTH
public String[] getParameterValues(String name);
public boolean isWindowStateAllowed(WindowState state);
public Map getParameterMap();
public boolean isPortletModeAllowed(PortletMode mode);
public boolean isSecure();
public PortletMode getPortletMode();
public WindowState getWindowState();
public void setAttribute(String name, Object o);
public PortletPreferences getPreferences();
public void removeAttribute(String name);
public PortletSession getPortletSession();
public String getRequestedSessionId();
public PortletSession getPortletSession(boolean
create);
public boolean isRequestedSessionIdValid();
public String getResponseContentType();
public String getProperty(String name);
public Enumeration getResponseContentTypes();
public Enumeration getProperties(String name);
public Locale getLocale();
public Enumeration getPropertyNames();
public Enumeration getLocales();
public PortalContext getPortalContext();
public String getScheme();
public String getAuthType();
public String getContextPath();
public String getServerName();
public String getRemoteUser();
public int getServerPort();
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 33
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
PortletRequest and Views
getResponseContentType()
preferred content type
getResponseContentTypes()
enumeration of acceptable content types in
descending order of preference
getLocale()
What locale is associated with this request?
We can use this and the content type to
determine which JSP page to dispatch.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 34
The PortletResponse
Interface
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
public interface PortletResponse
{
public void addProperty(String key, String value);
public void setProperty(String key, String value);
public String encodeURL(String path);
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 35
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The ActionRequest Interface
public interface ActionRequest extends PortletRequest
{
public InputStream getPortletInputStream()
throws IOException;
public void setCharacterEncoding(String enc)
throws UnsupportedEncodingException;
public BufferedReader getReader()
throws UnsupportedEncodingException, IOException;
public String getCharacterEncoding();
public String getContentType();
public int getContentLength();
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 36
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
ActionRequest
Provides access to the request body
only parameters are available from a
RenderRequest
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 37
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The ActionResponse Interface
public interface ActionResponse extends PortletResponse
{
public void setWindowState(WindowState windowState)
throws WindowStateException;
public void setPortletMode(PortletMode portletMode)
throws PortletModeException;
public void sendRedirect(String location)
throws IOException;
public void setRenderParameters(Map parameters);
public void setRenderParameter(String key, String value);
public void setRenderParameter(String key, String[]
values);
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 38
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
ActionResponse
send redirect
set portlet mode for the render call
set window state for the render call
set render parameters
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 39
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Render Parameters
Set via RenderURL or ActionResponse.
Preserved by the Portlet container, and
replayed when a Portlet is rendered.
A portlets render parameters are reset when
a Portlet URL is submitted to the Portlet
Container for that portlet.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 40
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The RenderRequest Interface
Just an empty extension of
PortletRequest
public interface RenderRequest extends PortletRequest
{
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 41
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The RenderResponse Interface
public interface RenderResponse extends PortletResponse
{
public static final String EXPIRATION_CACHE
public String getContentType ();
public PortletURL createRenderURL ();
public PortletURL createActionURL ();
public String getNamespace ();
public void setTitle(String title);
public void setContentType(String type);
public String getCharacterEncoding();
public java.io.PrintWriter getWriter() throws IOException;
public java.util.Locale getLocale();
public void setBufferSize(int size);
public int getBufferSize();
public void flushBuffer() throws IOException;
public void resetBuffer();
public boolean isCommitted();
public void reset();
public OutputStream getPortletOutputStream() throws IOException;
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 42
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
RenderResponse
setTitle(String)
sets the portlet's title
normally called by GenericPortlet.render()
must be called before committing portlet content
setContentType(String)
must be called before calling getWriter() or getOutputStream()
IllegalStateException thrown otherwise
must be a valid type for this response
see PortletRequest.getResponseContentTypes()
IllegalArgumentException thrown if invalid type
getWriter()/getOutputStream()
mutually exclusive
IllegalStateException if called before setContentType()
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 43
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The PortetURL Interface
public interface PortletURL
{
public void setWindowState(WindowState windowState)
throws WindowStateException;
public void setPortletMode(PortletMode portletMode)
throws PortletModeException;
public void setParameter(String name, String value);
public void setParameter(String name, String[] values);
public void setParameters(Map parameters);
public void setSecure(boolean secure)
throws PortletSecurityException;
public String toString();
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 44
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Portlet URLs
Action URLs cause the Portlet Container to clear the target portlets
render parameters, and invoke the target portlets processAction
method.
Render URLs cause the Portlet Container to invoke the target
portlets render method, with the specified set of render
parameters, if any.
Render URLs should not be associated with forms. Containers are
not required to add the form fields to the set of render parameters.
Portal controls (e.g., skin buttons) must be treated as render URLs
that preserve the existing set of render parameters.
PortletURL uses x-www-form-urlencoded encoding for
parameter names and values.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 45
The PortletPreferences
Interface
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
public interface PortletPreferences
{
public boolean isReadOnly(String key);
public String getValue(String key, String def);
public String[] getValues(String key, String[] def);
public void setValue(String key, String value)
throws ReadOnlyException;
public void setValues(String key, String[] values)
throws ReadOnlyException;
public Enumeration getNames();
public Map getMap();
public void reset(String key) throws ReadOnlyException;
public void store() throws IOException, ValidatorException;
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 46
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The PreferencesValidator
Interface
public interface PreferencesValidator
{
public void validate(PortletPreferences preferences)
throws ValidatorException;
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 47
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The PortletRequestDispatcher
Interface
public interface PortletRequestDispatcher {
public void include(RenderRequest request,
RenderResponse response)
throws PortletException, IOException;
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 48
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
PortletRequestDispatcher
Can encode parameters in a query string
aggregated with existing render parameters
override any existing parameter of that name
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 49
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Portlet JSP Tags
Assuming:
<%@ taglib uri=http://java.sun.com/portlet prefix=portlet %>
<portlet:defineObjects/>
<portlet:actionURL/>
<portlet:renderURL/>
<portlet:param/>
<portlet:namespace/>
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 50
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
<portlet:defineObjects/>
Defines implicit objects and enables the
environment for the other tags.
RenderRequest renderRequest
RenderResponse renderResponse
PortletConfig portletConfig
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 51
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
<portlet:actionURL/>
Creates an Action URL.
Attributes:
portletMode
windowState
secure
var
The body may include param tags:
<portlet:actionURL windowState = maximized
portletMode = edit>
<portlet:param name=action value=editStocks/>
</portlet:actionURL>
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 52
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
<portlet:renderURL/>
Creates an Render URL.
Attributes:
portletMode
windowState
secure
var
The body may include param tags:
<portlet:renderURL portletMode = view
windowState = normal>
<portlet:param name=showQuote value=myCompany/>
<portlet:param name=showQuote value=someOtherCo/>
</portlet:renderURL>
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 53
The PortletSession
Interface
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
public interface PortletSession
{
public static final int APPLICATION_SCOPE
public static final int PORTLET_SCOPE
public Object getAttribute(String name);
public Object getAttribute(String name,int scope);
public Enumeration getAttributeNames();
public Enumeration getAttributeNames(int scope);
public long getCreationTime();
public String getId();
public long getLastAccessedTime();
public int getMaxInactiveInterval();
public void invalidate();
public boolean isNew();
public void removeAttribute(String name) ;
public void removeAttribute(String name, int scope) ;
public void setAttribute(String name, Object value);
public void setAttribute(String name, Object value, int scope);
public void setMaxInactiveInterval(int interval);
public PortletContext getPortletContext ();
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 54
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Portlet Logging
PortletContext.log(String[, Throwable])
Understand for whom the Portlet Log is intended.
Provide content accordingly.
Remember the NullPointerException example!
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 55
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Portlet Services
IBM (WebSphere) specific, but being
discussed for wider deployment.
JNDI Lookup
Similar to local EJB, but with simple POJO
interfaces.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 56
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Cooperative Portlets
From a users perspective, the portal is the
application.
We would like to be able to construct new
business applications at the glass by
integrating portlets as components.
IBMs Cooperative Portlet technology uses
portlet filters, a portlet service, and WSDL to
support such at the glass integration.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 57
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
WSRP
WSRP (Web Services, Remote Portlets) is an
OASIS Specification for allowing a local
Portlet to proxy for a portlet running on a
remote Portal.
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 58
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Related Sessions
JSP 2.0 Tag Files: Custom Tags Made
Easy Noel J. Bergman
WSRP: Web Services for Remote
Portlets Dave Landers
Comparing Java Web Frameworks:
JSF, Struts, Spring, Tapestry and
WebWork Matt Raible
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 59
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Supplemental Information
The following slides provide additional reference information, but
are not intended to be presented during this session. Please feel
free to find me around the conference during the week.
Thank you for coming
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 60
The PortletSessionUtil
Class
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
public class PortletSessionUtil
{
public static String decodeAttributeName(String name)
public static int decodeScope(String name)
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 61
The PortletException
Class
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
public class PortletException extends Exception
{
public PortletException()
public PortletException(String text)
public PortletException(String text, Throwable cause)
public PortletException(Throwable cause)
public void printStackTrace()
public void printStackTrace(PrintStream out)
public void printStackTrace(PrintWriter out)
public Throwable getCause()
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 62
The ReadOnlyException
Class
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
public class ReadOnlyException extends PortletException
{
private ReadOnlyException()
public ReadOnlyException(String text)
public ReadOnlyException(String text, Throwable cause)
public ReadOnlyException(Throwable cause)
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 63
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The PortletModeException
Class
public class PortletModeException extends PortletException
{
public PortletModeException(String text, PortletMode mode)
public PortletModeException(String text, Throwable cause,
PortletMode mode)
public PortletModeException(Throwable cause, PortletMode mode)
public PortletMode getMode()
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 64
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The UnavailableException
Class
public class UnavailableException extends PortletException
public UnavailableException(String text)
public UnavailableException(String text, int seconds)
public boolean isPermanent()
public int getUnavailableSeconds()
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 65
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The ValidatorException
Class
public class ValidatorException extends PortletException
{
private ValidatorException()
public ValidatorException(String text, Collection failedKeys)
public ValidatorException(String text, Throwable cause,
Collection failedKeys)
public ValidatorException(Throwable cause,
Collection failedKeys)
public Enumeration getFailedKeys()
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 66
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The WindowStateException
Class
public class WindowStateException extends PortletException
{
public WindowStateException(String text, WindowState state)
public WindowStateException(String text, Throwable cause,
WindowState state)
public WindowStateException(Throwable cause, WindowState state)
public WindowState getState()
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 67
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The WindowState Class
public class WindowState
{
public final static WindowState NORMAL
public final static WindowState MAXIMIZED
public final static WindowState MINIMIZED
public WindowState(String name)
public String toString()
public int hashCode()
public boolean equals(Object object)
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 68
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
The PortletMode Class
public class PortletMode
{
public final static PortletMode VIEW
public final static PortletMode EDIT
public final static PortletMode HELP
public PortletMode(String name)
public String toString()
public int hashCode()
public boolean equals(Object object)
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 69
The PortalContext
Interface
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
public interface PortalContext
{
public String getProperty(java.lang.String name);
public Enumeration getPropertyNames();
public Enumeration getSupportedPortletModes();
public Enumeration getSupportedWindowStates();
public String getPortalInfo();
}
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 70
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Installing Pluto
Download binary distribution
Extract
Ensure that JAVA_HOME=<JAVA 5>
Start tomcat
Browse http://localhost:8080/pluto/portal
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 71
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Installing Jetspeed-2
Download binary distribution
Extract
Start database
Start tomcat
Browse http://localhost:8080/jetspeed/portal
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 72
Colorado Software Summit: October 23 28, 2005
Copyright 2005, DevTech
Installing Gridsphere
Install Ant binary distribution
Download binary distribution
Extract
Follow the Gridsphere QuickStart guide
http://www.gridsphere.org/gridsphere/gridspher
e?cid=quickstart&JavaScript=enabled
The easy way:
http://www.gridsphere.org
Select the download tab
Select Gridsphere QuickStart Portal
Noel Bergman Introduction to Portlet Programming with JSR-168
Page 73