SAS 9.1.3 Integration Technologies » SAS Web Infrastructure Kit: Developer's Guide


Developing Custom Portlets
Development Steps
Creating a Deployment Descriptor
Creating Display Resources Files
Developing the Presentation JSP Page
Creating Action Classes
Implementing Portlet Help
Creating a PAR File
Use Cases
Simple Display Portlet
Localized Portlet
Portlet Template (Editable Portlet)
Remote Portlet
Tips and Best Practices
Using the Portlet API
Sample Portlets
Localized Display Portlet (Welcome)
Interactive Form Portlet (FormExample)
Portlet Template, or Editable Portlet (DisplayURL)
Web Application (HelloUserWikExample)
Remote Portlet (HelloUserRemote
Portlet
Sample: Localized Display Portlet (Welcome Portlet)

Step 4: Create the Action Class

The Welcome portlet has its own action class, WelcomeAction, which provides support for localizing messages. This class extends com.sas.portal.portlet.HTMLPortletAction, which contains code to correctly display non-Latin1 character sets when the portal Web application displays the portlet in preview mode.

The source code for WelcomeAction follows. The box contains explanatory comments. For more information, see Creating Action Classes.


/** Copyright (c) 2003 by SAS Institute Inc., Cary, NC 27513.
 *  All Rights Reserved.
 */
package com.sas.portal.portlets.welcome;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sas.portal.portlet.HTMLPortletAction;
import com.sas.portal.portlet.NavigationUtil;
import com.sas.portal.portlet.PortletContext;

/**Action for the Welcome Portlet. This prepares the localized resource
 * bundles for use by the JSTL tags within the portlet's JSP.
 * @version 1
 */
public final class WelcomeAction extends HTMLPortletAction {

  /**
   * Configure the JSTL localization context for use in the Welcome
   * portlet. Returns the value of "display-page" from the portlet's
   * XML descriptor.
   *
   * @param request  The HttpServletRequest associated with the
   *                 method invocation
   * @param response HttpServletResponse associated with the
   *                 method invocation
   * @param context  PortletContext mapped to the request path
   *
   * @return java.lang.String - representing a valid URL.
   */
  public String service(HttpServletRequest request,
      HttpServletResponse response, PortletContext context)
    throws Exception{

In the following code, the NavigationUtil method uses the portlet's classloader to obtain the portlet's resource bundle. Using this bundle and the locale of the current user, it creates a new JSTL localization context. The localization context is made available to the portlet's JSP page with request scope.


	super.service(request, response, context);

NavigationUtil.prepareLocalizedResources(
   "com.sas.portal.portlets.welcome.res.Resources", request, context);

	//This comes from the portlet.xml.
        String url = (String) context.getAttribute("display-page");

        return url;
    }

}