Command types
WebSphere 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 WebSphere 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 WebSphere Commerce. Since WebSphere 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, WebSphere 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
WebSphere Commerce provides default commands and views which 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.
- Command context
Commands can obtain information using the command context. Examples of information available include the user's ID, the user object, the language identifier, and the store identifier.- Command framework
Command beans follow a specific design pattern. Every command includes both an interface class (for example, CategoryDisplayCmd) and an implementation class (for example, CategoryDisplayCmdImpl). From a caller's perspective, the invocation logic involves setting input properties, invoking an execute() method, and retrieving output properties.- Controller command programming model
The abstract class and interface are both found in the com.ibm.commerce.command package.- Task command programming model
A new task command should extend the abstract task command class com.ibm.commerce.command.TaskCommandImpl and implement an interface that extends the com.ibm.commerce.command.TaskCommand interface.- Data bean commands
A command data bean relies on a command to retrieve its data and is a more lightweight data bean. The command retrieves all attributes for the data bean at once, regardless of whether the JSP page requires them. As a result, for JSP pages that use only a selection of attributes from the data bean, a command data bean may be costly in terms of performance time. While access control can be enforced on a data bean level when using the smart data bean, this is not true for command data bean. Only use command data bean if using a smart data bean is impractical.Related concepts
Command context
Long-running controller commands
Data bean commands
Temporary changes to contextual information for URLsRelated tasks
Enabling WebSphere Commerce components