Datasheet

import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
/**
* @author Clay Richardson
* ExamplePortlet is a basic example of writing
* a portlet by extending GenericPortlet
*
*/
public class ExamplePortlet extends GenericPortlet {
/*
* This method overrides the doEdit of GenericPortlet
* This is called to provide the markup to be rendered when the
* portlet mode is PortletMode.EDIT
* <p>
* In this case, we will dispatch the method to a JSP
* located in the portlet root directory called “edit.jsp”
*/
protected void doEdit(
RenderRequest request,
RenderResponse response)
throws PortletException, IOException {
PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher(“/edit.jsp”);
prd.include(request, response);
}
We declare our ExamplePortlet, having it extend GenericPortlet. In here, we also override the doEdit
method, which handles rendering when the portlet is in EDIT mode.
/*
* This method overrides the doHelp of GenericPortlet
* This is called to provide the markup to be rendered when the
* portlet mode is PortletMode.HELP
* <p>
* In this case, we will dispatch the method to a JSP
* located in the portlet root directory called “help.jsp”
*/
protected void doHelp(
RenderRequest request,
RenderResponse response)
throws PortletException, IOException {
PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher(“/help.jsp”);
prd.include(request, response);
}
/*
* This method overrides the doEdit of GenericPortlet
* This is called to provide the markup to be rendered when the
* portlet mode is PortletMode.VIEW
12
Chapter 1
04 469513 Ch01.qxd 1/16/04 11:04 AM Page 12