Render Parameters Tutorial
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Tutorials

Basic

Hello World
Render Parameters
Action
Modes
JSP
Hello World
Basic
Action

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.

  1. Files in this tutorial
  2. Portlets are stateless
  3. Getting the value of a render parameter
  4. Setting the value of a render parameter - createRenderURL()

Files in this tutorial

WEB-INF/classes/example/HelloWorldPortlet.java Portlet
WEB-INF/web.xml web-app configuration

Portlets are stateless

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.

Getting the value of a render parameter

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);

    ...

Setting the value of a render parameter - createRenderURL()

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


Hello World
Basic
Action
Copyright © 1998-2005 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.