Add new business logic to a controller command

New business logic can be added before existing business logic, after existing logic, or both before and after. Suppose there is an existing WebSphere Commerce controller command, called ExistingControllerCmd. Following the WebSphere Commerce naming conventions, this controller command would have an interface class named ExistingControllerCmd and an implementation class named ExistingControllerCmdImpl. Now assume that a business requirement arises and you must add new business logic to this existing command. One portion of the logic must be executed before the existing command logic and another portion must be executed after the existing command logic.


About this task

The first step in adding the new business logic is to create a new implementation class that extends the original implementation class. In this example, you would create a new ModifiedControllerCmdImpl class that extends the ExistingControllerCmdImpl class. The new implementation class should implement the original interface (ExistingControllerCmd).

In the new implementation class we must create a new performExecute method to override the performExecute of the existing command. Within the new performExecute method, there are two ways in which we can insert your new business logic: we can either include the code directly in the controller command, or we can create a new task command to perform the new business logic. If we create a new task command then we must instantiate the new task command object from within the controller command.

The following code snippet demonstrates how to add new business logic to the beginning and end of an existing controller command by including the logic directly in the controller command:

The following code snippet demonstrates how to add new business logic to the beginning of an existing controller command by instantiating a new task command from within the controller command. In addition, you would also create the new task command interface and implementation class and register the task command in the command registry.

Regardless of whether you include the new business logic in the controller command, or create a task command to perform the logic, we must also update the CMDREG table in the WebSphere Commerce command registry to associate the new controller command implementation class with the existing controller command interface. The following SQL statement shows an example update:


Related tasks
Customizing existing controller commands