|
| |
Find this tutorial in: /usr/local/resin/webapps/resin-doc/portlet/tutorial/basic-jsp
Try the Tutorial
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() and render() See it in: WEB-INF/classes/example/HelloWorldPortlet.java
/**
* 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.
portlet JSP taglibrary See it in: hello.jsp
<%@ 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 init-param. This is a flexible
architecture, if a different jsp page is desired for the view it can be
specified without modifying the source code.
configure the portlet to use a different jsp
<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>
|
Try the Tutorial
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark,
and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc. | |
|