When customizing a Create
link, you can
define a service to initialize the new business object with certain
property values and child objects.
Create
links
are added to store pages to allow a business user to create new business
objects that affects the current page. For example, if the current
page displays an e-Marketing Spot, then a Create
link can help
the business user to create a web activity for that e-Marketing Spot.
The new web activity is initialized with the correct e-Marketing Spot.
This initialization is performed by the Populate New Object Service
(wcfPopulateNewObjectService) associated with the web activity object
definition. The primary ID of the e-Marketing Spot is passed to the
Populate New Object Service through the newObjectOption.marketingSpotId
parameter
that is included in the CreateBusinessObject URL.
To initialize
a new business object that is launched through a Create
link,
you must define a Populate New Object Service for that business object.
You must also include any parameters that are required by the Populate
New Object Service in the CreateBusinessObject URL.
To define
a Populate New Object Service, you must create and register a JSP
file that returns an XML document that contains serialized property
values and child objects. The XML document is parsed by the Management
Center framework and the new business object is initialized with these
property values and child objects.
Procedure
- Open
WebSphere Commerce Developer and switch to the Enterprise Explorer
view.
- Create the JSP file that returns an XML document that contains
serialized property values and child objects:
- Create a directory to store your custom JSP file at
the following path:
WCDE_installdir/workspace/LOBTools/WebContent/jsp/your_company_name/component_name/
Here
are two examples:
- WCDE_installdir/workspace/LOBTools/WebContent/jsp/MyCompany/Marketing/
- WCDE_installdir/workspace/LOBTools/WebContent/jsp/MyCompany/Catalog/
- Right-click the
component_name
directory;
then select .
- In the File name field, enter
a name for the new JSP file that follows this format:
PopulateNewobject_name.jsp,
for example, PopulateNewMarketingSpot.jsp or PopulateNewWebActivity.jsp.
- Click Finish.
- Create a JSP file that has these characteristics:
- Accepts parameters that are passed from the CreateBusinessObject
URL.
- Returns an XML document that follows the Management Center object
syntax that is described in Load services.
For example, the
Create
link for an
e-Marketing Spot initializes the new e-Marketing Spot with its name
prefilled in Management Center. To prefill the name, the CreateBusinessObject
URL contains a
NewObjectOption.marketingSpotName parameter,
as shown in the second-last line in this snippet:
<c:url var="clickToCreateURL" value="/cmc/CreateBusinessObject" context="/">
<c:param name="toolId" value="marketingManagement"/>
<c:param name="storeId" value="${storeId}"/>
<c:param name="languageId" value="${langId}"/>
<c:param name="storeSelection" value="prompt"/>
<c:param name="objectType" value="EMarketingSpot"/>
<c:param name="newObjectOption.marketingSpotName" value="${emsName}"/>
</c:url>
The following code snippet is the corresponding
JSP file. When this JSP file is called, the newObjectOption
parameter
value from the CreateBusinessObject URL is passed into the JSP in
the line that is labeled 1:
<?xml version="1.0" encoding="UTF-8"?>
<%@page contentType="text/xml;charset=UTF-8"%>
<%@ taglib uri="http://commerce.ibm.com/foundation" prefix="wcf"%>
<object>
<name><wcf:cdata data="${param.marketingSpotName}"/></name> 1
</object>
- Save and close the JSP file.
- Register the JSP file in the struts-extension.xml configuration
file:
- Expand .
- Open the struts-extension.xml file
in a text editor.
- In the
<action-mappings>
section,
add an action (global forward) that maps to your JSP file by using
this format:<action path="pathName" forward="pathToJSP" />
Where:
- pathName
- A name that is used to map to the JSP file. Use the name of the
JSP file as the path name, starting with a forward slash, for example,
/PopulateNewEMarketingSpot
.
- pathToJSP
- The path to the JSP file that you created in this task. The path
must start from /LOBTools/WebContent/.
For example, this action maps the JSP file that
outputs the
Name field value for an e-Marketing
Spot:
<action path="/PopulateNewEMarketingSpot" forward="/jsp/commerce/marketing/restricted/PopulateNewEMarketingSpot.jsp" />
- Save and close the struts-extension.xml configuration
file.
- Define the PopulateNewObjectService in the object definition
file for the target business object:
- Open the object definition file for the target business
object.
You can find object definition files for business
objects that are shipped with WebSphere Commerce at the following
path:
WCDE_installdir/workspace/LOBTools/WebContent/config/commerce/component/objectDefinitions/
- In the object definition file, define
the PopulateNewObjectService as a child element of the object definition.
Use this format:
<PopulateNewObjectService url="pathName">
...
</PopulateNewObjectService>
The pathName
value is the action path
that you defined in the struts-extension.xml file
in the previous step.
The following code snippets
show how the PopulateNewObjectService is declared in the e-Marketing
Spot and web activity object definitions to support click-to-edit:
- For e-Marketing Spots:
<PopulateNewObjectService url = "/cmc/PopulateNewEMarketingSpot">
<ServiceParam name = "storeId"/>
</PopulateNewObjectService>
- For Web activities:
<PopulateNewObjectService url = "/cmc/PopulateNewWebActivity">
<ServiceParam name = "storeId"/>
<ServiceParam name = "path" objectPath = "path" checkObjectDefinition = "true" propertyName = "objectType" optional = "true"/>
<ServiceParam name = "viewEMarketingSpot" objectPath = "path/viewEMarketingSpot" checkObjectDefinition = "true" propertyName = "objectType" optional = "true"/>
</PopulateNewObjectService>
- Save and close the object definition file.
What to do next
After you complete your customization: