Tutorial: Extending a Struts action
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.
This tutorial demonstrates how to extend Struts actions in the context of WebSphere Commerce store development. Specifically, we will create a new action class, MyNewAction, that extends the WebSphere Commerce BaseAction class... when a customer first arrives at a store page from one of a predefined set of referring Web sites (for instance, business partners or partner search engines), MyNewAction will create a cookie to store the referring Web site's URL; this information can later be used to pay royalties to the referring Web site if the customer makes a purchase within a predetermined period of time or simply to gather statistics. You will then configure an existing starter store action to use MyNewAction as its implementation class.
Learning objectives
- Extend an action, as opposed to a command, because you are only targeting requests entering the system through the Web channel.
- Use cookies in the implementation, because to associate a referral with a specific user and you want this association to persist between shopping sessions.
Time required
Expect this tutorial to take about 1 hour to complete.
Audience
This tutorial is intended for WebSphere Commerce Store developers.
Prerequisites
Before beginning this tutorial ensure that you have:
- An understanding of the Java programming language
- An understanding of Struts
- Familiarity with Java servlet programming
Ensure you enable Struts Development in WebSphere Commerce Developer, if it is currently disabled:
- Select Window > Preferences.
- Select General > Capabilities.
- Click Advanced... and select Web Developer (advanced) > Struts Development, if it is currently disabled.
- Click OK to accept the changes and close the Advanced Capabilities Settings window.
- Click OK to accept the changes and close the Preferences window.
Lessons in this tutorial
- Prepare the workspace
This topic explains how to prepare the workspace.
- Create an action extending BaseAction
This section is about creating a Java package for the class, creating the MyNewAction class and adding the referrer-cookie functionality.
- Configure TopCategoriesDisplay to use MyNewAction
By default, all WebSphere Commerce actions use com.ibm.commerce.struts.BaseAction as their implementation class. In this step, we will configure the TopCategoriesDisplay action, responsible for invoking the main page of the consumer direct sample store, to use the extension, com.ibm.commerce.sample.struts.MyNewAction, instead. These changes affect all stores that use the TopCategoriesDisplay action.
- Test the implementation
This tutorial lesson is about testing the implementation.