|
| |
Find this tutorial in: /usr/local/resin/webapps/resin-doc/portlet/tutorial/basic-render
Try the Tutorial
Render parameters are used to maintain state.
This tutorial adds the concept of "identity" and "color" to the basic Hello
World example, the identity and color are maintained as render parameters.
Just like Servlets a Portlet does not maintain state within the Portlet
object. Many requests, from many different users, may be using an instance of
a portlet at the same time.
In this tutorial, the "identity" and "color" are two values to
contain the state of the portlet. The portlet provides links to change the
color or identity, and maintains the identity and color from request to
request.
The value of a render parameter is obtained from the
request
object using request.getParameter(name).
Getting the value of a render parameter See it in: WEB-INF/classes/example/HelloWorldPortlet.java
public void render(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{
String identity = request.getParameter("identity");
if (identity == null)
identity = "World";
String color = request.getParameter("color");
if (color == null)
color = "silver";
...
out.println("Hello, " + identity + ".");
out.println("Your favorite color is " + color);
...
|
The value of a render parameter can be changed on a subsequent request with the
use of
response.createRenderURL() .
response.createRenderURL() returns a
PortletURL .
The PortletURL is used to set render parameters for the
next request, the toString() method is used to generate
the appropriate url.
response.createRenderURL() See it in: WEB-INF/classes/example/HelloWorldPortlet.java
...
String identity = request.getParameter("identity");
String color = request.getParameter("color");
...
// url links to change the name
PortletURL harryUrl = response.createRenderURL();
harryUrl.setParameter("identity", "Harry");
harryUrl.setParameter("color", color);
PortletURL ronUrl = response.createRenderURL();
ronUrl.setParameter("identity", "Ron");
ronUrl.setParameter("color", color);
...
out.println("<li><a href='" + harryUrl.toString() + "'>Harry</a>");
out.println("<li><a href='" + ronUrl.toString() + "'>Ron</a>");
...
|
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. | |
|