10.2.5 ActionEvent

In the IBM portlet API, the ActionEvent object is used to retrieve an ActionString. The ActionString is used to determine which form made the request. With JSR 168 you should test the request parameters for the Submit button value. Example 10-7 Illustrates a JSR form and the processAction method. As you can see, the submit button in the form has the name of the FORM_SUBMIT static variable. Then, in the processAction method, we test if this parameter exists. If so, we know that the form associated with this submit button was submitted and we can process accordingly.

Example 10-7 JRS 168 Action Handling

JSP Form
<FORM method="POST" action="<portlet:actionURL/>">
<LABEL  for="<%=MyJSRPortletPortlet.FORM_TEXT%>">Enter order  id:</LABEL><BR>
<INPUT name="<%=MyJSRPortletPortlet.FORM_TEXT%>" type="text"/>
<INPUT name="<%=MyJSRPortletPortlet.FORM_SUBMIT%>" type="submit" value="Submit"/>
</FORM>

Portlet Code
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
 if( request.getParameter(FORM_SUBMIT) != null ) {
  // FORM_SUBMIT form was submitted
  //Do something!
 }

Create new unique static variables for each of the submit buttons (or any other field that will result in a request parameter) used to create an action request. Then modify your processAction method to test for these parameters and process the data as need.


Redbooks
ibm.com/redbooks