Initializing a new business object for a Create link

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

  1. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  2. Create the JSP file that returns an XML document that contains serialized property values and child objects:
    1. 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/
    2. Right-click the component_name directory; then select New > File.
    3. 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.

    4. Click Finish.
    5. 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>
    6. Save and close the JSP file.
  3. Register the JSP file in the spring-extension.xml configuration file:
    1. Expand LOBTools > WebContent > WEB-INF.
    2. Open the spring-extension.xml file in a text editor.
    3. Add your JSP file to the configuration.
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
        <bean id="/SerializePromotionElement-promotion_element_subtype" 
         class="org.springframework.web.servlet.mvc.ParameterizableViewController">
         <property name="viewName" value="pathToJSP"/>
        </bean>
      </beans>
    4. Save and close the spring-extension.xml configuration file.
  4. Define the PopulateNewObjectService in the object definition file for the target business object:
    1. 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/WEB-INF/src/xml/commerce/component/objectDefinitions/

    2. 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 spring-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>
    3. Save and close the object definition file.

What to do next

After you complete your customization: