Tutorials > Program model > Extend the object model and modifying an existing task command

< Previous | Next >


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

  1. 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

  2. Import the sample Java source code

    1. Expand the WebSphereCommerceServerExtensionsLogic project.

    2. From the src folder's pop-up menu, select Import.

    3. From the Select an import source list, select General > File System and click Next.

    4. In the From directory field, navigate to the temporary directory and select the Javafiles directory. For example: D:\temp\notcompletedsourcecode\objectmodel\Javafiles.

    5. Click Select All and click Finish.

    6. 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.

  3. 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.

    1. Expand the Stores > WebContent > consumer_direct_name where consumer_direct_name is the name of the consumer direct sample store.

    2. From the consumer_direct_name folder's pop-up menu, select Import.

    3. From the Select an import source list, select General > File System and click Next.

    4. In the From directory field, navigate to the temporary directory and select the storeassets directory. For example: D:\temp\notcompletedsourcecode\objectmodel\storeassets.

    5. Click Select All.

    6. Deselect ordergift.properties and click Finish. Two new JSPs, OrderSummaryDisplayInclude.jsp and OrderDetailDisplayInclude.jsp are imported into the include folder.

  4. Import the properties file

    1. Expand the Stores > Java Resources: src > consumer_direct_name where consumer_direct_name is the name of the consumer direct sample store.

    2. From the consumer_direct_name folder's pop-up menu, select Import.

    3. From the Select an import source list, select General > File System and click Next.

    4. In the From directory field, navigate to the temporary directory and select the storeassets directory. For example: D:\temp\notcompletedsourcecode\objectmodel\storeassets.

    5. Select ordergift.properties and click Finish.

  5. 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:

    1. Start the test environment.

    2. Open a browser and type the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp

    3. 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.

    4. Click Submit Query to run the SQL statement.

  6. 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:

    1. 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.

    2. Create a backup copy of thePaymentMethodsDisplay.jsp file:

      1. Select the PaymentMethodsDisplay.jsp file and click Edit > Copy , then Edit > Paste.

      2. In the Name Conflict window, enter PaymentMethodsDisplay_bak.jsp and click OK.

    3. 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>
      

    4. 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 -->
      

    5. Save the file.

  7. Modify a JSP page for gift message output

    In this step we will modify the OrderConfirmationDisplay.jsp file to display the gift message information.

    1. 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.

    2. Create a backup copy of the OrderConfirmationDisplay.jspfile:

      1. Select the OrderConfirmationDisplay.jsp file and click Edit > Copy , then Edit > Paste.

      2. In the Name Conflict window, enter OrderConfirmationDisplay_bak.jsp and click OK.

    3. In the OrderConfirmationDisplay.jsp file, locate the following lines:

      </tbody>
      </table>
      <!--MAIN CONTENT ENDS HERE-->
      

    4. 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-->   
      

    5. Save the file.

< Previous | Next >


+

Search Tips   |   Advanced Search