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
Development Steps: Developing Action Classes

Creating a Portlet Action Class

When developing a local portlet, you can implement one or more action classes for the portlet. If you use an action class, then the following requirements must be met:

  • You must specify the class in your portlet deployment descriptor file (portlet.xml).

  • The class must implement com.sas.portal.portlet.PortletActionInterface.

  • The class can extend DefaultPortletAction or HTMLPortletAction in com.sas.portal.portlet.

The DefaultPortletAction and HTMLPortletAction contain two simple methods for setting and getting an instance of com.sas.portal.portlet.PortletActionInfoInterface, as shown in this example:

public void setInfo(PortletActionInfoInterface pai) {
        _actionInfo = pai;
    }
    public PortletActionInfoInterface getInfo() {
        return _actionInfo;
    }

The primary method, called service(), runs before the portlet is displayed and every time the portlet is redisplayed. For example, it runs after a user interacts with the portlet or with a different portlet on the same page.

The service() method is provided with the HttpServletRequest, HttpServletResponse, and PortletContext objects. From the PortletContext object, you can obtain the HttpSession object, which provides access to the most important servlet objects.

Your service() method must return a string representing a valid URL for the portlet. Typically, the URL is the name of the portlet's JSP page. If your initializer places the display-page property of the portlet.xml into the PortletContext, then you can obtain the URL as in this example:

String url = (String) context.getAttribute("display-page");

If user interaction with your portlet requires a different URL string, then you can return that URL instead.

The service() method can handle any kind of exception subclass that is thrown by code within your action. If your portlet action needs to throw an exception, then you can use the portlet error handler. For more information, see Error Handling.