Creating a dynamic action form for a JSP page

In this lesson, you replace the existing Contact Us JSP page with a new JSP page, called MyContactUsDisplay.jsp. The MyContactUsDisplay.jsp page contains an HTML form and replaces the default Contact Us page of the Madisons starter store, ContactDisplay.jsp. You create a dynamic action form to hold the HTML form data in the MyContactUsDisplay.jsp page which collects user input to be processed by the logic you enabled in the previous lesson.

About this task

The MyContactUsDisplay.jsp file contains a form as its main element. The form is defined with the Struts html:form tag. The action attribute of the html:form element specifies the action to which the form is submitted. The action is identified by the path attribute of its action configuration element. The action element can also be used to establish the appropriate action form and scope for your HTML form. The form comprises two text input fields, one text-area input field, and a submit button, rendered with Struts html:text, html:textarea, and html:submit tags. The form also includes three hidden fields, defined with the Struts html:hidden tag, which are used to pass along WebSphere Commerce context parameters.

Procedure

  1. The struts-config-ext.xml file should still be open for editing in the Struts Configuration File Editor. If not, expand Stores/WebContent/WEB-INF. Right-click the struts-config-ext.xml file, and select Open With > Struts Configuration File Editor.
  2. Click the Form Beans tab. In the Form Beans section, click Add to create a Form Bean. Replace the default bean name with the name MyContactUsForm.
  3. In the Form Bean Attributes section, for the Type, enter org.apache.struts.action.DynaActionForm.
  4. In the Form Beans tab, click the Form Properties tab.
  5. In the DynaBeans section, select MyContactUsForm.
  6. Create the properties for the MyContactUsForm form:
    1. In the Form Properties section click Add to create the name property for the MyContactUsForm form.
      1. For the Name field, enter name.
      2. Select the name property, and in the Form Property Attributes section, for the Type field, enter java.lang.String
    2. In the Form Properties section click Add to create the email property for the MyContactUsForm form.
      1. For the Name field, enter email.
      2. Select the name property, and in the Form Property Attributes section, for the Type field, enter java.lang.String
    3. In the Form Properties section click Add to create the comment property for the MyContactUsForm form.
      1. For the Name field, enter comment.
      2. Select the name property, and in the Form Property Attributes section, for the Type field, enter java.lang.String
    4. In the Form Properties section click Add to create the storeId property for the MyContactUsForm form.
      1. For the Name field, enter storeId.
      2. Select the name property, and in the Form Property Attributes section, for the Type field, enter java.lang.String
    5. In the Form Properties section click Add to create the langId property for the MyContactUsForm form.
      1. For the Name field, enter langId.
      2. Select the name property, and in the Form Property Attributes section, for the Type field, enter java.lang.String
    6. In the Form Properties section click Add to create the catalogId property for the MyContactUsForm form.
      1. For the Name field, enter catalogId.
      2. Select the name property, and in the Form Property Attributes section, for the Type field, enter java.lang.String
    7. Save your changes. You have created the properties for JSP page dynamic form.
  7. Click the Action Mappings tab. In the Action Mappings section, select MyContactUsCmd.
  8. In the Form Bean Specification section associate the Form Bean with the MyContactUsForm form:
    1. In the Form Bean Name field enter the name MyContactUsForm
    2. In the Scope field, select request.
    3. Ensure the Validate check box is not selected.
  9. Switch to the Source view and verify that the MyContactUsCmd action definition now looks as follows:
    
    <action path="/MyContactUsCmd"
    type="com.ibm.commerce.struts.BaseAction" 
            parameter="com.ibm.commerce.sample.commands.MyContactUsCmd"
            name="MyContactUsForm" 
            scope="request"
            validate="false"> 
    </action>
    
  10. Save your changes and leave the Struts Configuration File Editor open.