Example: Adding an action button to the Campaigns list page
This scenario is a generic example describing how to add an action button to a list page. You can adapt this scenario it to other components, with different targets by changing the appropriate assets.
The campaigns component in WebSphere Commerce organizes campaign activities, and acts as a method by which to sort statistical information associated with marketing efforts. Typically, it will not be necessary to customize the campaigns component.
This scenario adds an action button to the Campaigns list page, which links directly to the Web activity wizard. This customization is useful insofar as it provides another way of accessing this tool.
- Create a label for the new button. Labels for buttons, and all
other interface elements are stored in properties files, which are
also referred to as resource bundles. To protect your customized data
from being overwritten during migration to a future version, or during
installation of a future fix pack, separate your customization from
the WebSphere Commerce assets. This procedure creates a properties
file, in a new folder, within the WebSphere Commerce development environment:
- Open the WebSphere Commerce development environment
- Navigate to the WebSphereCommerceServerExtensionsLogic project.
- Navigate to the src folder.
- Right-click on the src folder, and select New, and then Package.
- In the Name Field on the New Java Package
dialog, enter a unique name. For the purposes of this scenario, enter
com.myCompany.campaigns.properties
, where myCompany represents some custom directory name. Packages created by IBM, and included in WebSphere Commerce follow a naming convention which begins, "com.ibm..." - Click Finish to create the package.
- Right-click on the com.myCompany.campaigns.properties folder, and select New, and then Other. In the New dialog, click Simple, File, and then Next.
- In the File name field, enter a unique
name. For the purposes of this scenario, enter
CampaignsRB_locale.properties
, where locale represents the locale from which your business users will access the WebSphere Commerce Accelerator. - Click Finish to create the file and open it in an editor.
- To simplify future maintenance, it is a good idea to include comments
in this new file. This is optional, though strongly recommended. At
the top of this file, include some comments similar to the following
to clarify this file's purpose:
# # Customized properties for Campaigns # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
- Scroll down and create a "Button definitions" section for the
file, and insert a label for your new button. This should look similar
to the following sample:
# # Button definitions # newCustomActivity = Create Web Activity
- Save the file, but do not close the development environment.
This addresses the label in the language for the locale you specified when you created the file. If you wanted to enter a string in more than one language, you would have to perform this step for each language, creating a file for each corresponding locale.
If a business user attempts to access this page using a locale for which there is no explicit support, the tools framework will default to the CampaignsRB.properties file, which will not contain a corresponding string. You should ensure that you create a version of the properties file for every locale from which you expect users to access it.
- When you create a custom properties file, you must update the
appropriate resources.xml file so that the new file is available to
the tools within the component. This is not done within the development
environment. To make this update:
- Create a new directory under the WC_eardir/xml directory. For the purposes of this scenario, name the directory, WC_eardir/xml/myCustomXML, where myCustomXML represents some custom directory name.
- Repeat this process until you have created the following
path:
WC_eardir/xml/myCustomXML/tools/campaigns/
- Copy the WC_eardir/xml/tools/campaigns/resources.xml file, and move the file to the WC_eardir/xml/myCustomXML/tools/campaigns/ directory.
- Open the new resources.xml file in an editor.
- Scroll down to the "Resource bundle" section of the file, and
update the code so that it matches the following sample:
where myCompany represents your company name.<resourceBundle name="campaignsRB"> <bundle>com.ibm.commerce.tools.campaigns.properties.CampaignsRB</bundle> <bundle>com.myCompany.campaigns.properties.CampaignsRB</bundle> </resourceBundle>
- Save the file.
- Update the Campaign List definition XML file to add
the new button, Create Web Activity. Again,
to protect your customized data, it must be created in a safe place,
separate from the WebSphere Commerce assets. This procedure creates
a Campaign List XML definition file, in the same WC_eardir/xml/myCustomXML/tools/campaigns
folder used in step 2. This is not done within the development environment.
To add the button:
- Change to the WC_eardir/xml/tools/campaigns directory.
- Copy WC_eardir/xml/tools/campaigns/CampaignList.xml to the new WC_eardir/xml/myCustomXML/tools/Campaigns directory. Do not change the file name.
- Open the CampaignList.xml file in an editor.
- Scroll down to the code segment about buttons. Add the following
code:
The value for the name attribute must match the value of the key that we inserted into the properties file in step 1. Also, the action matches the action defined in the Campaign Activity list page's corresponding XML file, also located in the WC_eardir/xml/tools/campaigns directory. This button performs the same function as the Create button on that page. Finally, we have set the value for the selection attribute to 'single', which means that the action is only available when a single campaign is selected. In other situations this value could be set to either 'none', or 'multiple', which would specify that the button was only available when either no campaigns were selected, or when more than one campaign was selected, respectively.<menu name="newCustomActivity" action="basefrm.newInitiative()" selection="single" />
- Save the file.
- Creating a custom XML file in a custom directory requires that
you update the instance XMLPath setting. This setting governs the
locations in which the application attempts to locate XML files. It
functions in a manner like a Java classpath setting. To update the
XMLPath setting:
- Change to the WC_eardir/xml/config directory.
- Open the wc-server.xml file in an editor.
- Scroll down to the <ToolsGeneralConfig> section of the file,
and update the XMLPath by specifying your custom directory name to
the value. For example, if the original XMLPath value is
and your custom directory is myCustomXML, then change the XMLPath value toXMLPath="tools;tools/devtools;WEB-INF/xml/tools;WEB_INF"
XMLPath="myCustomXML/tools;tools;tools/devtools;WEB-INF/xml/tools;WEB_INF"
- Save the file.
Attention: Applying fix packs, or performing migration might overwrite any changes made to this file.
- Update the CampaignList.jsp with a new algorithm to handle the
new button. To protect the custom code, this procedure creates a new
JSP which contains the logic:
- In the WebSphere Commerce development environment, navigate to the CommerceAccelerator/Web Content/tools directory.
- Right-click on the folder, and select New, and
then Folder. In the Folder name field,
enter
custom
. - Navigate to the Web Content/tools/campaigns folder.
- Right-click on the CampaignList.jsp file, and select Copy.
- Right-click on the Web Content/tools/custom folder, and select Paste.
- Navigate to the Web Content/tools/custom folder.
- Double-click the new file to open it in an editor.
- Update your JSP. Scroll down to the section of the file in which
the JavaScript functions are defined, and update it so that it contains
the following JavaScript (lines may be split here for presentation
purposes):
function newInitiative () { var url = "<%= UIUtil.getWebappPath(request) %>DialogView?XMLFile=campaigns.InitiativeDialog"; top.setContent("<%= UIUtil.toJavaScript((String)campaignsRB.get(CampaignConstants.MSG_CREATE_INITIATIVE)) %>", url, true); }
This code can be found in the InitiativeList.jsp file in the same directory, and copied from that source.
- Also, because the custom file is in a different location, you
have to update the following path in the JSP to reflect the original
location. Search for the following include statement:
and change it to:<%@ include file="common.jsp" %>
<%@ include file="../campaigns/common.jsp" %>
- Save the file, but do not close the development environment.
- Update the view that corresponds to the page in the Struts configuration
file to map the new JSP file to their corresponding view. The CampaignListView
command must be overwritten in the configuration file. Add the entries
to the struts-config-ext.xml file to point to your customized JSP
page. All customization changes should be made in struts-config-ext.xml,
not to struts-config.xml. To register the new views:
- In the WebSphere Commerce development environment, navigate to the CommerceAccelerator/Web Content/WEB-INF folder.
- From the struts-config-ext.xml file's pop-up menu, select Open.
- Add the following code:
<global-forwards> <forward name="CampaignListView" path="/tools/custom/CampaignList.jsp" className="com.ibm.commerce.struts.ECActionForward" /> </global-forwards>
- Test your customization in your development environment. To complete
this test:
- Stop and restart your development WebSphere Commerce instance. Refer to the for details about how to stop and restart this instance.
- Launch the WebSphere Commerce Accelerator.
- From the Marketing menu, select Campaigns. The new button should display on this page.
- Select a campaign, and click the new Create Web Activity button. This should launch the Web activity wizard. If this works, then the customization has been a success, and you can proceed to propagate all of the changes you made to the development environment to the production environment as detailed in the following steps. If this fails, you will have to determine the cause of the error, and debug.
- Export the updated assets:
- Right-click the new CampaignList.jsp file and select Export.
The Export Wizard opens.
In the Export wizard:
- Select File system and click Next.
- The CampaignList.jsp is selected.
- Navigate to the WebSphereCommerceServerExtensionsLogic/src/com /myCompany/campaigns/properties folder, and select the myCampaignsRB_locale.properties file.
- Select Create directory structure for selected files.
- In the To directory field, enter a temporary
directory into which these resources will be placed. For example,
enter
C:\ExportTemp\StoreAssets
- Click Finish.
- If prompted, create the specified directory.
- Right-click the new CampaignList.jsp file and select Export.
The Export Wizard opens.
- Transfer the updated assets to the production environment. To
transfer the files:
- On the target machine, locate the WebSphere Commerce instance .ear directory, WC_eardir.
- Copy the files exported in step 9,
above, into the following directories:
- CampaignList.jsp
- WC_eardir/CommerceAccelerator.war/tools/custom
- myCampaignsRB_locale.properties
- WC_instance_name.ear/properties/com/myCompany/campaigns /properties
- Transfer the following files to your production environment:
- /xml/myCustomXML/tools/campaigns/CampaignList.xml
- Copy to WC_installdir/xml/tools/custom
- /xml/WC_eardir/xml/tools/campaigns/resources.xml
- Copy to WC_eardir/xml/tools/campaigns
- Update the WebSphere Commerce configuration file, so that it reflects the updated XMLPath value.
- Copy your change to the Struts configuration file, to your production environment.
- Package and deploy the updated assets.
- Restart your WebSphere Commerce instance.