resin Portlet JSP Tutorial tutorial hello

Portlet JSP that renders the view for HelloWorldPortlet web-app configuration

JSP is often the most convenient way to construct the view for a portlet. A portlet can dispatch to a jsp to provide the view in a fashion very similar to a servlet or a classic model-2 architecture like Struts.

The dispatch() method of the HelloWorldPortlet use the Portlet API to dispatch to a view, and the render() method does the dispatch.

/** * Dispatch to a jsp or servlet. */ protected void dispatch( RenderRequest request, RenderResponse response, String path ) throws PortletException, IOException { PortletContext ctx = getPortletContext(); PortletRequestDispatcher dispatcher = ctx.getRequestDispatcher(path); dispatcher.include(request, response); } public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException { prepareObjects(request, response); dispatch(request, response, _view); }

The standard JSP functionality, including JSTL and EL are available in a JSP that a portlet uses for the view.

Portlet request attributes, set in the portlet with request.setAttribute( "name", value ), are available in the JSP as request attributes request.getAttribute("name") and EL variables ${'${'}name}.

There is also a portlet JSP tag library that defines a small number of portlet specific tags. The most useful of the portlet tags are those that are provided for creating render and action urls.

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> ... <portlet:actionUrl var="submitUrl" portletMode="edit"/> ... <portlet:renderUrl var="editUrl" portletMode="edit"/>

The HelloWorldPortlet is written so that it provides a default path for the jsp that can be overriden by an . This is a flexible architecture, if a different jsp page is desired for the view it can be specified without modifying the source code.

<servlet servlet-name="hello" servlet-class="com.caucho.portal.generic.PortletServlet"> <init> <portlet resin:type="example.HelloWorldPortlet"> <view>/custom/hello.jsp</view> </portlet> </init> </servlet>