Command types
HCL Commerce commands are Java beans that contain the programming logic associated with handling a particular request. Commands perform a specific business process, such as adding a product to the shopping cart, processing an order, updating a customer's address book, or displaying a specific product page.
Depending on its nature, a command can:
- Call enterprise beans to perform database operations.
- Call one or more task commands that are assigned to process tasks to process and write information to the database.
- Return a view task on completion of a controller command.
The HCL Commerce programming model defines the following command types:
- Controller commands
- Encapsulate the logic related to a particular business process. Examples of controller commands include the OrderProcessCmd command for order processing and the LogonCmd that allows users to log on. In general, a controller command contains the control statements (for example, if, then, else) and invokes task commands to perform individual tasks in the business process. Upon completion, a controller command returns a view name. Based upon the view name, the store identifier, and the device type, the solution controller determines the appropriate implementation class for the view and then invokes it.
- Task commands
- Implement a specific unit of application logic. In general, a controller command and a set of task commands together implement the application logic for a URL request. Task commands are executed in the same container as the controller command.
- Data bean commands
- Are invoked by the data bean manager when a JSP page needs to instantiate a data bean. The primary function of a data bean command is to populate the fields of a data bean with data from a persistent object.
- View commands
- View commands, used to compose a view as a response to a client request, are deprecated in this release of HCL Commerce. Since HCL Commerce is a Struts application the view command has been replaced by global forwards. For compatibility with previous releases, view command of previous releases will continue to work.
When creating new business logic for your e-commerce application, it is expected that you might need to create new controller and task commands.
New commands must implement their corresponding interface (which, in turn, should extend an existing interface). To simplify command writing, HCL Commerce includes an abstract implementation class for each type of command. New commands should extend these classes.
The following table shows which implementation class a new command should extend and which interface it should implement:
Command type | Example command name | Extends | Implements example interface |
---|---|---|---|
Controller command | MyControllerCmdImpl | com.ibm.commerce.command.ControllerCommandImpl | MyControllerCmd |
Task command | MyTaskCmdImpl | com.ibm.commerce.command.TaskCommandImpl | MyTaskCmd |
Data bean command | MyDataBeanCmdImpl | com.ibm.commerce.command.DataBeanCommandImpl | MyDataBean |
Default commands and views
HCL Commerce provides default commands and views which you can use in your store. These default commands and views are listed in the Struts configuration file for the Web application.
Additionally, many of the views used in starter store were created specifically for the store. These views are listed in the struts-config-update.tpl.xml file packaged as part of the store archives. If a required command or view is not provided, you can add your own to the store archive's Struts configuration file.