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: Portlet Template, or Editable Portlet (DisplayURL)

OK and Cancel Actions

The DisplayURL portlet's OkAction class is invoked when a user clicks the OK button on the editor display page. The CancelAction class is invoked when a user clicks the Cancel button on the editor display page. The source code for both classes follows.


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

import com.sas.portal.portlet.configuration.ConfigurationFactory;
import com.sas.portal.portlet.configuration.Configuration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sas.portal.Logger;
import com.sas.portal.portlet.PortletContext;


/**
 * Action class that processes the Ok action from the editor. It
 * persists the user-specified URL, sets up the display model, then
 * instructs the portlet container to present the display page.
 */
public final class OKAction extends BaseAction
{
   private final String _loggingContext = this.getClass().getName();

   /**
    * Service the portlet request.
    *
    * @param request the HttpServletRequest
    * @param response the HttpServeltResponse
    * @param context the PortletContext
    * @return the URL to call
    */
   public String service (HttpServletRequest request,
                          HttpServletResponse response,
                          PortletContext context) throws Exception
   {
       super.service(request, response, context);

       String url = request.getParameter(Initializer.DISPLAY_URL_KEY);
       context.setAttribute(Initializer.DISPLAY_URL_KEY, url);

        // save the URL parameter
       Configuration config = ConfigurationFactory.getConfiguration(
          context);
       config.setAttribute(Initializer.DISPLAY_URL_KEY, url);
       ConfigurationFactory.storeConfiguration(context, config);

        if (Logger.isDebugEnabled(_loggingContext)){
          Logger.debug("Display portlet URL: " + url, _loggingContext);
        }

       // back to the default, display, mode
       // context.resetMode();

       return (String)context.getAttribute("display-page");
   }
}


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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import com.sas.portal.Logger;
import com.sas.portal.portlet.PortletContext;


/**
 * Action class that processes the Cancel action from the editor. It
 * sets up the display model then instructs the portlet container to 
 * present the display page.
 */
public final class CancelAction extends BaseAction
{
//    private final String _loggingContext = this.getClass().getName();

    /**
     * Service the portlet request.
     *
     * @param request the HttpServletRequest
     * @param response the HttpServeltResponse
     * @param context the PortletContext
     * @return the URL to call
     */
    public String service(HttpServletRequest request,
                          HttpServletResponse response,
                          PortletContext context) throws Exception
    {
        super.service(request, response, context);

        // back to the default, display, mode
        // context.resetMode();
        return (String)context.getAttribute("display-page");
    }
}