Datasheet
* <p>
* In this case, we will dispatch the method to a JSP
* located in the portlet root directory called “view.jsp”
*/
protected void doView(RenderRequest request,
RenderResponse response)
throws PortletException, IOException {
PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher(“/view.jsp”);
prd.include(request, response);
}
Similarly, we provide the behavior required to render the portlet when it is in its HELP and VIEW modes.
/* This method was overriden to specify
* the title programmatically
* This may be useful if you are going to
* have parameters in your title like:
* “News on 9/11/2001”
*/
protected String getTitle(RenderRequest request) {
return “Example Portlet”;
}
/* This method is the meat of the portlet
* manipulations of the portlet’s state are done
* through this method.
*
* For simplicity sake, we will parse a param
* that indicates the portlet mode to which the
* portlet should be set.
*
*/
public void processAction(ActionRequest request,
ActionResponse response)
throws PortletException, IOException {
PortletMode mode =
new PortletMode(request.getParameter(“mode”));
response.setPortletMode(mode);
}
}
Finally, we specify overriding the getTitle method, allowing for more complex logic in rendering the
title (such as displaying the current date) rather than displaying the static title declared in the deploy-
ment descriptor. We also handle the
processAction method, which is responsible for the behavior in
response to an
ActionRequest.
The preceding code shows a basic implementation of a portlet by writing a class that extends
Generic
Portlet
. This portlet doesn’t do much beyond dispatch to other JSPs based on its mode (and set its
name programmatically), but you see the crux of implementing a portlet.
13
The Java Portlet API (JSR 168)
04 469513 Ch01.qxd 1/16/04 11:04 AM Page 13