Enabling business process portlets that use the Basic portlet model

Portlets created using the Basic code generation model option require additional enablement to handle business processes.

When creating a business process portlet using the New Portlet Project wizard or New Portlet wizard, you can specify either a Faces or a Basic portlet model to generate code for process initiation or task processing. However, for a Basic portlet, after the wizard generates the base code, there are additional steps that perform to enable the business process portlet.

  1. To enable a process initiation portlet, follow these steps:

    1. Create user interface for an input message in the portlet JSP file. For example, add a <form> tag with <input> tags for the input message, and an action URL.

    2. Implement processAction() (JSR 168 or JSR 286 API) or actionPerformed() (IBM® portlet API) to store request parameter values in corresponding parts of the input message.

      Note: If the input message has message parts that are complex types, request parameters must be stored in a complex type created and stored to the corresponding message part. Refer to the example below.

    3. Call initiateProcess() inprocessAction() (JSR 168 API or JSR 286) or actionPerformed() (IBM portlet API). For Websphere Portal example:

      public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
      		if( request.getParameter("initiateProcess") != null ) {
      			PortletSession session = request.getPortletSession();
      			DataObject inputMessage = (DataObject)session.getAttribute(ProcessInitiationHelper.PROCESS_INPUT_MESSAGE);
      			inputMessage.set("Destination", request.getParameter("Destination"));
      			inputMessage.set("StartDate", request.getParameter("StartDate"));
      			inputMessage.set("Reason", request.getParameter("Reason"));
      			DataObject flightReservation = inputMessage.createDataObject("FlightReservation");
      			flightReservation.set("startdate", request.getParameter("FlightReservation.startdate"));
      			flightReservation.set("starttime", request.getParameter("FlightReservation.starttime"));
      			flightReservation.set("enddate", request.getParameter("FlightReservation.enddate"));
      			flightReservation.set("endtime", request.getParameter("FlightReservation.endtime"));
      			flightReservation.set("sourceairport", request.getParameter("FlightReservation.sourceairport"));
      			flightReservation.set("destinationairport", request.getParameter("FlightReservation.destinationairport"));
      			flightReservation.set("airline", request.getParameter("FlightReservation.airline"));
      			flightReservation.set("seatclass", request.getParameter("FlightReservation.seatclass"));
      			inputMessage.set("FlightReservation", flightReservation);
      			DataObject requestor = inputMessage.createDataObject("Requestor");
      			requestor.set("id", request.getParameter("Requestor.id"));
      			inputMessage.set("Requestor", requestor);
      			ProcessInitiationHelper helper = getProcessInitiationHelper(request);
      			helper.initiateProcess();
      		}
      	}
      For a WebSphere® V6.0 or later, example:

      public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
        if( request.getParameter("initiateProcess") != null ) {
          PortletSession session = request.getPortletSession();
          Map inputMessage = (Map)session.getAttribute(ProcessInitiationHelper.PROCESS_INPUT_MESSAGE);
          inputMessage.put("Destination", request.getParameter("Destination"));
          inputMessage.put("StartDate", request.getParameter("StartDate"));
          inputMessage.put("Reason", request.getParameter("Reason"));
          FlightReservation flightReservation = new FlightReservation();
          flightReservation.setStartdate(request.getParameter("FlightReservation.startdate"));
          flightReservation.setStarttime(request.getParameter("FlightReservation.starttime"));
          flightReservation.setEnddate(request.getParameter("FlightReservation.enddate"));
          flightReservation.setEndtime(request.getParameter("FlightReservation.endtime"));
          flightReservation.setSourceairport(request.getParameter("FlightReservation.sourceairport"));
          flightReservation.setDestinationairport(request.getParameter("FlightReservation.destinationairport"));
          flightReservation.setAirline(request.getParameter("FlightReservation.airline"));
          flightReservation.setSeatclass(request.getParameter("FlightReservation.seatclass"));
          inputMessage.put("FlightReservation", flightReservation);
          Employee requestor = new Employee();
          requestor.setId(request.getParameter("Requestor.id"));
          inputMessage.put("Requestor", requestor);
          ProcessInitiationHelper helper = getProcessInitiationHelper(request);
          helper.initiateProcess();
        }
      }

  2. To enable a task processing portlet, follow these steps:

    1. Create user interfaces for the input and output messages in the portlet JSP file. For example, add a <form> tag with <input> tags for the output message, and an action URL.

    2. Implement processAction() (JSR 168 API or JSR 286) or actionPerformed() (IBM portlet API) to store request parameter values in corresponding parts of the output message.

      Note: If the input message has message parts that are complex types, request parameters must be stored in a complex type created and stored to the corresponding message part.

    3. Call processTask() and, optionally, closePage(), in processAction() (JSR 168 or JSR 286 API) or actionPerformed() (IBM portlet API). For a WebSphere Portal example:

      public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
      		TaskProcessingHelper taskProcessingHelper = getTaskProcessingHelper(request);
      		if (taskProcessingHelper != null)
      			taskProcessingHelper.receivePageContext(request);
      		if( request.getParameter("processTask") != null ) {
      			PortletSession session = request.getPortletSession();
      			DataObject outputMessage = (DataObject)session.getAttribute(TaskProcessingHelper.TASK_OUTPUT_MESSAGE);
      			outputMessage.set("Worker", request.getParameter("Worker"));
      			outputMessage.set("managerApproved", new Boolean(request.getParameter("managerApproved") != null));
      			taskProcessingHelper.processTask();
      			taskProcessingHelper.closePage(request, response);
      		}
      	}
      For a WebSphere Portal V6.0, or later, example:

      public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
        TaskProcessingHelper taskProcessingHelper = getTaskProcessingHelper(request);
        if (taskProcessingHelper != null)
          taskProcessingHelper.receivePageContext(request);
        if( request.getParameter("processTask") != null ) {
          PortletSession session = request.getPortletSession();
          Map outputMessage = (Map)session.getAttribute(TaskProcessingHelper.TASK_OUTPUT_MESSAGE);
          outputMessage.put("Worker", request.getParameter("Worker"));
          outputMessage.put("managerApproved", new Boolean(request.getParameter("managerApproved") != null));
          taskProcessingHelper.processTask();
          taskProcessingHelper.closePage(request, response);
        }
      }

 

Related concepts

Process initiation helper classes

Task processing helper classes

 

Related tasks

Creating a business process portlet project

Adding data access to business process portlets

Creating user interfaces for business processes

Developing business process portlets

Inserting images in portlet JSP files

 

Related reference

WebSphere Portal Documentation Library