Tutorials > Program model > Create new business logic
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:
- How to modify the controller command to include additional response properties in the TypedProperty.
- How to modify the JSP page to retrieve information from the response properties using the JSTL expression language.
Procedure
- Modify the MyNewControllerCmdImpl class:
- Navigate to WebSphereCommerceServerExtensionsLogic > src > com.ibm.commerce.sample.commands.
- Double-click MyNewControllerCmdImpl.java and select its performExecute method in the Outline view.
- 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.
- Save the changes.
- Update the MyNewJSPTemplate.jsp file:
- If the JSP pages are not already open:
- Navigate to the Stores > WebContent > ConsumerDirect_name directory.
- From the MyNewJSPTemplate_All.jsp file's pop-up menu, select Open With > Page Designer.
- From the MyNewJSPTemplate.jsp file's pop-up menu, select Open With > Page Designer.
- 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.
- Save the changes.
- Test the modifications to the controller command and to the JSP page:
- Restart the test environment.
- Navigate to the Stores > WebContent > ConsumerDirect_name directory.
- 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.
- 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: