Show TOC Start of Content Area

Background documentation Servicing Action Requests  Locate the document in its SAP Library structure

In traditional Web applications, when a client request is processed, this usually means that some underlying business logic is executing. The result of this processing is set in the response or in the session and is returned to the client or forwarded to another servlet or JSP. With portlets, business logic is implemented in the processAction method. An action URL created by the portlet triggers an invocation of this method. Typically, the response to an action request results in changing the portlet’s state based on the information provided in the information in the action request parameters. The processAction method receives two parameters: ActionRequest and ActionResponse. Portlets access information such as action request parameters, window state, and portlet mode using the ActionRequest object.

Example

The following code accesses request parameters:

  public void processAction (ActionRequest request, ActionResponse                                    response)

    throws PortletException  {

   

    Enumeration paramNames = request.getParameterNames();

    while (paramNames.hasMoreElements) {

       String paramName = (String)paramNames.nextElement();

       String paramValue = request.getParameter(paramName);

     }

   }

The ActionRequest object provides access to request parameters, the portal context, the portlet session, and portlet preferences data.

Example

While processing an action request, a portlet may instruct the portal/portlet-container to redirect the user to a specific URL:

String path = actionRequest.getContextPath() +                                                           “/userInfo.jsp?userId=5”;

actionResponse.sendRedirect(path);

Caution

The sendRedirect method cannot be invoked if one of the following methods of the ActionResponse interface has been called:

       setPortletMode

       setWindowState

       setRenderParameter

       setRenderParameters

The ActionResponse object allows a portlet to change its portlet mode and window state.

Example

  public void processAction (ActionRequest request, ActionResponse                                          response)

    throws PortletException  {

 

    String wMode = request.getParameter(“w_mode”);

    if  (wMode.equals(“help”) && (request.isPortletModeAllowed(PorlteMode.HELP))) {

      response.setPortletMode(PortletMode.HELP);

      response.setWindowState(WindowState.NORMAL);

    } else {

      response.setWindowState(WindowState.MAXIMIZED);

    } 

  }

The change of portlet mode and window state will be effective for the next render request the portlet receives. While processing action requests, a portlet may also set render parameters in the ActionResponse object. These parameters will be the parameters that the portlet will receive with the RenderRequest within the render call.

Example

// key under which to store the shared data in the session

  public final static String MANAGER = "manager";

  public final static String DEPARTMENT = "department";

 

  public void processAction(ActionRequest request, ActionResponse actionResponse)

      throws PortletException {

    // get the selected manager

    String manager = request.getParameter(MANAGER);

    String department = request.getParameter(DEPARTMENT);

    if (manager != null) {

      request.getPortletSession().setAttribute(MANAGER, manager,

          PortletSession.APPLICATION_SCOPE);

      actionResponse.setRenderParameter(DEPARTMENT, department);

    }

  }

 

 

 

 

End of Content Area