Action 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
Render Parameters
Basic
Modes

Find this tutorial in: /usr/local/resin/webapps/resin-doc/portlet/tutorial/basic-action
Try the Tutorial

An action request is a request for the portlet to do something before it is rendered. An action request to a portlet invokes the processAction method before invoking the render method.

This tutorial adds an HTML form to the hello world portlet. The HTML form allows the user to set the "identity" and "color". The submission of the form is an action, it is a request to do something.

  1. Files in this tutorial
  2. The form uses an Action URL
  3. Action parameters come from the browser
  4. Render parameters are reset

Files in this tutorial

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

The form uses an Action URL

An action URL is created with response.createActionURL(). The resulting url indicates to the portal that it should invoke the processAction() method in the portlet before invoking the render() method.

A form that uses an action parameter must always use the POST method. The portal may encode some special parameters in the url, and the use of the GET method would overwrite those parameters.

Creating an action URL
See it in: WEB-INF/classes/example/HelloWorldPortlet.java

    ...

    PortletURL submitUrl = response.createActionURL();

    out.println("<form method='POST' action='" + submitUrl + "'>");
    out.println("Name:");
    out.println("<input type='text' name='identity' value='" + identity + "'>");
    out.println("<br>");
    out.println("Color:");
    out.println("<input type='text' name='color' value='" + color + "'>");
    out.println("<br>");
    out.println("<input type='submit'");
    out.println("</form>");

    ...

The resulting HTML form sent to the browser
<form method='POST' action='/resin-doc/portlet/tutorial/basic-lifecycle/hello?____A='>
Name:
<input type='text' name='identity' value='World'>
<br>
Color:
<input type='text' name='color' value='silver'>
<br>
<input type='submit'
</form>

When the form submit button is pressed, the action url is used. The action url indicates to the portal that it is an action request. Responding to the action request, the portal invokes the processAction() method before invoking the render() method.

The resulting HTML demonstrates how the portal might add parameters to the url. The url that is in the action attribute contains the ____A= parameter. The parameter has been added to mark the requet as an action request.

Action parameters come from the browser

The portlet's implentation of processAction() uses response.getParameter() to get the submitted form parameters.

Action parameters
See it in: WEB-INF/classes/example/HelloWorldPortlet.java

  public void processAction(ActionRequest request, ActionResponse response) 
    throws PortletException, IOException
  {
    // get the values submitted with the form

    String identity = request.getParameter("identity");
    String color = request.getParameter("color");

    ...

There is an important distinction here - during processAction() the parameters are the parameters submitted from a form, during render() the parameters are render parameters and the parameters submitted from a form are no longer available.

Render parameters are reset

If the portlet is invoked from an action url, all render parameters are reset. The implementation of the processAction must use response.setRenderParameter() to set render parameters for the susbsequent call to render().

Action parameters
See it in: WEB-INF/classes/example/HelloWorldPortlet.java

  public void processAction(ActionRequest request, ActionResponse response) 
    throws PortletException, IOException
  {

    ...

    response.setRenderParameter("identity", identity); 
    response.setRenderParameter("color", color); 
  }

Try the Tutorial


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