Tutorial: Extending the object model and modifying an existing task command
Attention: This tutorial is currently under revision. The content might contain errors or inaccuracies. Subscribe to this page to be notified when an updated version is available.
In this tutorial, you address a requirement to collect gift card information for orders. The information that must be collected is the name of the recipient, the name of the sender and two messages. The information will be collected when the customer submits the order. You will create a new database table to store the gift order information and a new entity bean to access the data.
Learning objectives
In addition to creating the new entity bean, you extend the existing ExtOrderProcessCmdImpl task command. At the end of the order process command, ExtOrderProcessCmdImpl is provided as an extension point to customized code. The extension is used to instantiate a new data bean that corresponds to the new table and it is used to update the gift information in the database. After completing this tutorial you should be able to extend the object model:
- Extend the object model by creating a new database table
- Create an entity bean
- Modify an existing task command.
Time required
Expect this tutorial to take about 1 hour to complete.
You can load the completed tutorial code instead of performing each step. After loading the completed tutorial code into the workspace, you can run the code as if you performed each step in the tutorial. However, in order to fully attain the learning objectives, it is recommended that you perform the tutorial step by step.
Audience
This tutorial is intended for WebSphere Commerce store developers who are responsible for extending the object model.
Prerequisites
Saving the sample codeBefore beginning this tutorial, download the WCSample.zip package that contains the starting point for these programming tutorials. Save this file onto the development machine. As an example, you might save the file into the WCDE_INSTALL/ directory.
Knowledge prerequisitesBefore starting this tutorial you should have a basic understanding of:
- Rational Application Developer.
- The Java programming language.
- The database type, Apache Derby, , DB2, , or Oracle, used in the WebSphere Commerce development environment.
Code prerequisites
- This tutorial does not require that you have completed previous programming tutorials. If you have completed those tutorials, there is no harm in leaving the code in the workspace, as it will not conflict with this tutorial.
- Before starting this tutorial, have published a store based upon the consumer direct sample store. Within this store, be able to complete a purchase (for example, browse the catalog, add items to the shopping cart, check out and see the order confirmation).
Lessons in this tutorial
- Create and populating the XORDGIFT table
In this step, you create the XORDGIFT table that will hold the gift message information. This table contains the following six columns: ORDERSID, RECEIPTNAME, SENDERNAME, MSGFIELD1, MSGFIELD2, and OPTCOUNTER. ORDERSID is the primary key and the foreign key that references the ORDERS_ID field of the ORDERS table. This foreign key associates the gift message to its corresponding order.
- Create the OrderGift entity bean
The OrderGift entity bean allows you to access the information in the XORDGIFT table. Within the entity bean we will create fields that map to the columns in the XORDGIFT table.
- 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, we 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.
- Test the new gift message functionality
This sections tests the new gift message functionality.
- Deploy the gift message functionality
This section describes how to deploy the new business logic into a store running on a remote WebSphere Commerce Server. You must have created a store based on the consumer direct sample store on the remote WebSphere Commerce Server before starting these deployment steps. Within that store, be able to complete a purchase.
- Load the completed tutorial code
This section explains how to load the completed code into WebSphere Commerce Developer instead of completing each tutorial step. You can load the completed code into WebSphere Commerce Developer instead of completing each tutorial step.