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 you must perform to enable the business process portlet.
- To enable a process initiation portlet, follow these steps:
- 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.
- Implement processAction() (JSR 168 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.
- Call initiateProcess() in processAction() (JSR
168 API) or actionPerformed() (IBM portlet API). For 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();
}
}
- To enable a task processing portlet, follow these steps:
- 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 input message, and an action URL.
- Implement processAction() (JSR 168 API)
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.
- Call processTask() and, optionally, closePage(),
in processAction() (JSR 168 API) or actionPerformed() (IBM portlet
API). For 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);
}
}