Tutorials > Program model > Extend the object model and modifying an existing task command
Integrate the OrderGift entity bean into the shopping flow
In this step, we will integrate the OrderGift entity bean into the regular shopping flow of the store. In this section, you will add new logic at the end of the OrderProcess business process to update the XORDGIFT database table with information related to the gift order: Create a new OrderGiftDataBean data bean; Create a new MyExtOrderProcessCmdImpl task command; Modify the OrderSubmitForm.jsp display page.
Procedure
- Extract the sample source code
Navigate to WCSample.zip and extract the following files to a temporary directory, for example D:\temp :
- notcompletedsourcecode\objectmodel\Javafiles\com\ibm\commerce\sample\databeans\OrderGiftDataBean.java
- notcompletedsourcecode\objectmodel\Javafiles\com\ibm\commerce\sample\commands\MyExtOrderProcessCmdImpl.java
- notcompletedsourcecode\objectmodel\storeassets\include\OrderSummaryDisplayInclude.jspf
- notcompletedsourcecode\objectmodel\storeassets\include\OrderDetailDisplayInclude.jsp
- notcompletedsourcecode\objectmodel\storeassets\ordergift.properties
- Import the sample Java source code
- Expand the WebSphereCommerceServerExtensionsLogic project.
- From the src folder's pop-up menu, select Import.
- From the Select an import source list, select General > File System and click Next.
- In the From directory field, navigate to the temporary directory and select the Javafiles directory. For example: D:\temp\notcompletedsourcecode\objectmodel\Javafiles.
- Click Select All and click Finish.
- Two new packages, com.ibm.commerce.sample.commands and com.ibm.commerce.sample.databeans display in the Enterprise Explorer view.
The OrderGiftDataBean to facilitate displaying attributes from the OrderGift entity bean on a JSP display page.
The ExtOrderProcessCmdImpl command is provided as the extension point to this business process. Following the programming model, to extend this logic you create a new implementation class of the task command and include the new logic in this class. You must then update the command registry to associate the new implementation class with the ExtOrderProcessCmd interface.
Once you have imported the code for this new command, you can examine the source to see what the command does. Notice that the command calls the performExecute() method of its superclass to ensure that any processing from that command is executed. It then includes the logic to set the gift order information into the new data bean.
- Import the sample JSP pages
If you have not published a store based upon the consumer direct sample store, do so before continuing with the tutorial.
- Expand the Stores > WebContent > consumer_direct_name where consumer_direct_name is the name of the consumer direct sample store.
- From the consumer_direct_name folder's pop-up menu, select Import.
- From the Select an import source list, select General > File System and click Next.
- In the From directory field, navigate to the temporary directory and select the storeassets directory. For example: D:\temp\notcompletedsourcecode\objectmodel\storeassets.
- Click Select All.
- Deselect ordergift.properties and click Finish. Two new JSPs, OrderSummaryDisplayInclude.jsp and OrderDetailDisplayInclude.jsp are imported into the include folder.
- Import the properties file
- Expand the Stores > Java Resources: src > consumer_direct_name where consumer_direct_name is the name of the consumer direct sample store.
- From the consumer_direct_name folder's pop-up menu, select Import.
- From the Select an import source list, select General > File System and click Next.
- In the From directory field, navigate to the temporary directory and select the storeassets directory. For example: D:\temp\notcompletedsourcecode\objectmodel\storeassets.
- Select ordergift.properties and click Finish.
- Modify the command registry
In this section, we will modify the command registry so that the new MyExtOrderProcessCmdImpl implementation class executes instead of the original ExtOrderProcessCmdImpl implementation class. In the following steps you modify the CMDREG table so that all stores use the new implementation class.
To modify the command registry:
- Start the test environment.
- Open a browser and type the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp
- In the input box, enter the following SQL statement:
insert into CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION, CLASSNAME, TARGET) values (CD_storeent_ID, 'com.ibm.commerce.order.commands.ExtOrderProcessCmd', 'This is a new task command for the extending an entity bean tutorial.', 'com.ibm.commerce.sample.commands.MyExtOrderProcessCmdImpl', 'local');where CD_storeent_ID is the unique identifier of the store.
- Click Submit Query to run the SQL statement.
- Modify a JSP page for gift message input
In this step, we will modify the PaymentMethodsDisplay snippet, so that the customer can input message information for the gift order as well as view the information in a summary page. The strategy for modifying this pages is to include an additional JSP page that include the new information for the gift message. This new page, OrderDetailDisplayInclude.jsp, uses the JSTL to display the new information.
To modify the display pages:
- In the Enterprise Explorer view, navigate to Stores > WebContent > consumer_direct_name > Snippets > EDP > PaymentMethods, where consumer_direct_name is the name of the consumer direct sample store.
- Create a backup copy of thePaymentMethodsDisplay.jsp file:
- Select the PaymentMethodsDisplay.jsp file and click Edit > Copy , then Edit > Paste.
- In the Name Conflict window, enter PaymentMethodsDisplay_bak.jsp and click OK.
- In the PaymentMethodsDisplay.jsp file, locate the following lines of code:
<%-- **************************** * Start: This form is invoked on the click of Add button after entering the mandatory payment fields *************************** --%> <c:set var ="edp_PIInfo_Form" value="PIInfo_${paymethodCnt.count}" scope="request"/> <form Name="<c:out value="${edp_PIInfo_Form}"/>" METHOD=Post action="PIAdd"> <input type="hidden" name="orderId" value="<c:out value="${orderIdRn}"/>" /> <input type=hidden name="URL" value="OrderDisplay?allocate=*n&backorder=*n&reverse=*n&remerge*n" /> <input type=hidden name="storeId" value="<c:out value="${WCParam.storeId}" />" /> <input type=hidden name="langId" value="<c:out value="${CommandContext.languageId}" />" /> <input type=hidden name="catalogId" value="<c:out value="${WCParam.catalogId}" />" /> <input type=hidden name="payMethodId" value="<c:out value="${edp_Info.policyName}" />" /> <input type=hidden name="payment_method" value="<c:out value="${edp_Info.policyName}" />" /> <input type=hidden name="policyId" value="<c:out value="${edp_Info.policyId}"/>" /> <input type=hidden name="errorViewName" value="DoPaymentErrorView" /> <input type="hidden" name="valueFromProfileOrder" value="Y" /> <%-- ******************** * Start: gets and includes the full path of the attribute page name with the extension as .jsp ******************** --%> <%-- If remaining amount is negative amount, just leave it blank --%> <c:set var ="edp_PayMethodAmount" value="${remainingAmt}" scope="request"/> <c:set var ="edp_OrderTotalAmount" value="${edp_OrderBean.grandTotal.amount}" scope="request"/> <c:if test="${edp_PayMethodAmount lt 0}" > <c:set var="edp_PayMethodAmount" value="0.00" scope="request"/> </c:if> <c:if test="${!empty edp_Info.attrPageName}"> <c:set var="edp_AttrPageFullPath" value="${snippetJspStoreDir}Snippets/EDP/PaymentMethods/${edp_Info.attrPageName}.jsp" /> <c:set var="paymentTCInfo" value="${edp_Info}" scope="request"/> <c:if test="${edp_Info.policyName eq temp_edp_ProtocolData.payment_method}"> <c:set var="edp_ProtocolData" value="${temp_edp_ProtocolData}" scope="request"/> </c:if> <c:set var ="edp_PI_Form" value="${edp_PIInfo_Form}" scope="request"/> <c:import url="${edp_AttrPageFullPath}" > <c:param name="paymentTCId" value="${edp_Info.TCId}" /> <c:param name="showPONumber" value="${showPONumber}" /> <c:param name="currentBillingAddress" value="${billingAddressId}"/> </c:import> <c:if test="${edp_Info.policyName eq edp_ProtocolData.payment_method}"> <c:remove var="edp_ProtocolData" scope="request"/> </c:if> </c:if> <%-- ******************** * End: gets and includes the full path of the attribute page name with the extension as .jspd ******************** --%> </form>
- Add the following code just before the </form> tag:
<!-- Start: Include the tutorial JSP --> <jsp:include page="../images/locale/screensnap/../include/OrderSummaryDisplayInclude.jsp" flush="true" /> <!-- End: Include the tutorial JSP -->
- Save the file.
- Modify a JSP page for gift message output
In this step we will modify the OrderConfirmationDisplay.jsp file to display the gift message information.
- Expand the Stores > WebContent > consumer_direct_name > WebContent > ShoppingArea > CheckoutSection > StandardCheckoutSubsection folder, where consumer_direct_name is the name of the consumer direct sample store.
- Create a backup copy of the OrderConfirmationDisplay.jspfile:
- Select the OrderConfirmationDisplay.jsp file and click Edit > Copy , then Edit > Paste.
- In the Name Conflict window, enter OrderConfirmationDisplay_bak.jsp and click OK.
- In the OrderConfirmationDisplay.jsp file, locate the following lines:
</tbody> </table> <!--MAIN CONTENT ENDS HERE-->
- Add a new row to the end of the table and an import statement to display the gift message information by adding the following code before the </tbody> line:
<tr><td> <!-- Start: Include the tutorial JSP --> <jsp:include page="../images/locale/screensnap/../include/OrderDetailDisplayInclude.jsp" flush="true" /> <!-- End: Include the tutorial JSP --> </td></tr>The resulting code looks like the following:
<tr> <td> <!-- Start: Include the tutorial JSP --> <jsp:include page="../images/locale/screensnap/../include/OrderDetailDisplayInclude.jsp" flush="true" /> <!-- End: Include the tutorial JSP --> </td> </tr> </tbody> </table> <!--MAIN CONTENT ENDS HERE-->
- Save the file.