Tutorials > Program model > Create new business logic

< Previous | Next >


Use a TypedProperties object to pass information from MyNewControllerCmd to

In this step, we will use a TypedProperties object for response properties and how to extract information from this object onto the JSP page.

Pass information using a TypedProperties object

In this section, we will modify MyNewControllerCmdImpl to pass information to the JSP page. Specifically, we will modify the command to add additional name-value pairs into the existing rspProp TypedProperties object that stores response properties from the command. Within the JSP page, you use the Java Server Tag Library (JSTL) expression language to extract the information from the response properties.

In this section of the tutorial, we will learn the following:


Procedure

  1. Modify the MyNewControllerCmdImpl class:

    1. Navigate to WebSphereCommerceServerExtensionsLogic > src > com.ibm.commerce.sample.commands.

    2. Double-click MyNewControllerCmdImpl.java and select its performExecute method in the Outline view.

    3. In the source code for the performExecute method, uncomment Section 2, introducing the following code into the method:

      /// Section //////////
      
          /// The controller command passes variables to the JSP page
      
        /// add additional parameters in controller command to rspProp 
        ///  for response
          String message1 = "Hello from IBM!";
        
        rspProp.put("controllerParm1", message1);
        rspProp.put("controllerParm2", "Have a nice day!");
      
      /// End of section////////
      

      The preceding code snippet stores two new parameters in the response properties object. This object is eventually passed to the view.

    4. Save the changes.

  2. Update the MyNewJSPTemplate.jsp file:

    1. If the JSP pages are not already open:

      1. Navigate to the Stores > WebContent > ConsumerDirect_name directory.

      2. From the MyNewJSPTemplate_All.jsp file's pop-up menu, select Open With > Page Designer.

      3. From the MyNewJSPTemplate.jsp file's pop-up menu, select Open With > Page Designer.

    2. Copy SECTION 4 from MyNewJSPTemplate_All.jsp file into your new MyNewJSPTemplate.jsp file. Place the new text between the <!-- SECTION 4 --> and <!-- END OF SECTION 4 --> markers. This action introduces the following text into MyNewJSPTemplate.jsp:

      <!-- SECTION 4 -->
      
      <h3><fmt:message key="ParametersFromCmd" bundle="${tutorial}" />
      </h3>
      
      <fmt:message key="ControllerParm1" bundle="${tutorial}" />
      <c:out value="${controllerParm1}"/>
      <br />
       
      <fmt:message key="ControllerParm2" bundle="${tutorial}" />
      <c:out value="${controllerParm2}"/>
      <br />
      <br />
        
      <!-- END OF SECTION 4 -->
      

      This section uses the JSTL expression language to get and display the values that were passed in from the controller command.

    3. Save the changes.

  3. Test the modifications to the controller command and to the JSP page:

    1. Restart the test environment.

    2. Navigate to the Stores > WebContent > ConsumerDirect_name directory.

    3. Select the index.jsp file and from its pop-up menu select Run As > Run on Server. The store home page displays in the Web browser.

    4. In the Web browser enter the following URL: http://localhost/webapp/wcs/stores/servlet/MyNewControllerCmd After a few seconds, the new JSP page displays, as shown in the following screen capture:

< Previous | Next >


+

Search Tips   |   Advanced Search