Feature Pack 6 or later

Creating a controller JSP file to retrieve URL information for in-context preview

For in-context preview to function properly for your business object, ensure that the URL information is returned as part of the object. One way to retrieve URL information is to create a custom controller JSP file to work with a serialization JSP file to transform WebSphere Commerce services nouns into XML for display in the Management Center. The controller JSP sends the nouns from BOD responses to a serialization JSP file for XML formatting.

Note: Creating a serialization JSP file is only one of many ways to transform URL information into XML. You might have custom services or methods to transform URL information. For example, if you have a custom wcf url tag that can return URL information in the expected format, a serialization JSP file is not required. You can implement the url tag in the controller JSP file.

About this task

When a business user is working on an object and launches store preview, a call is made to retrieve the URL information of the object. To retrieve the in-context preview URL information, the URL information must be in the XML format that is required by Management Center. To transform this URL information to the XML format, a controller JSP and serialization JSP file are required. The controller JSP determines how to handle the transformation request and sends the content to the correct serialization JSP file. The serialization JSP file is used to receive object properties from Nouns, and transform this URL information for use in the Management Center store preview.

When the call to retrieve URL information occurs, the controller JSP invokes the wcf:getData tag library to retrieve the noun that is used for the Management Center object. In the wcf:getData tag, the expressionBuilder parameter defines the query template to run. The query template is mapped to the SQL statement that retrieves the data. For more information, see Management Center Web application.

After you create the controller JSP file, the file must be registered for your object in the struts-extension.xml file for customization. When you register the controller JSP file and use this Struts configuration file for customization, this file takes priority over all other Struts configuration files. For more information about the Struts configuration file, see customizing the Web application configuration. For more information about how Struts are used in WebSphere Commerce, see WebSphere Commerce Struts framework.

Procedure

  1. Create a controller JSP file.
    1. In the Enterprise explorer view, expand LOBTools > WebContent > jsp > your_company_name > component_name. Create the directory structure if it does not exist.
    2. Right-click the component_name directory; then select New > File.
    1. In the File name field, enter a name for the new controller JSP file that follows this format: GetObjectNamePageSeoUrl.jsp.
      For example, for a recipe collection object, name the JSP file GetRecipeCollectionPageSeoUrl.jsp.
    2. Click Finish.
    3. Develop the code for your controller JSP file.
      Ensure that in the controller JSP file, you define the wcf:getData tag to retrieve the noun for the new Management Center object from the WebSphere Commerce services. Within the wcf:getData tag, define the correct type of data that is to be retrieved, and the correct expression builder. The expression builder is defined in the get-data-config.xml file for the component and defines the query template to run to retrieve URL information. The following code snippets are examples of expression builders that are predefined for existing business objects that in-context preview supports.
      • For catalog page-related objects:
        <wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogGroupType[]"
        	var="category" expressionBuilder="getCatalogGroupSEOByID">
      • For catalog entry page-related objects:
        <wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType[]"
        	var="catalogEntry" expressionBuilder="getCatalogEntrySEOByID">
      • For static page-related objects:
        <wcf:getData type="com.ibm.commerce.infrastructure.facade.datatypes.OnlineStoreType[]"
        	var="staticPagesSEO" expressionBuilder="findAllSEOStaticPageURLKeywordSummaryByStoreID">
    4. Save and close the file.
  2. Register the controller JSP file in the struts-extension.xml configuration file.
    1. In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF.
    2. Open the struts-extension.xml file in a text editor.
    3. In the <action-mappings> section, add an action mapping to register the controller JSP file.
      <action path="pathName" forward="pathToJSP" />
      pathName
      A name that is used to map to the JSP file.
      pathToJSP
      The path to the JSP file, starting from LOBTools > WebContent.
      For example, to create a mapping to a JSP file that retrieves the URL for a recipe collection page, add the following code to the file:
      <action path="/GetRecipeCollectionPageSeoUrl" forward="/jsp/your_company_name/component_name/GetRecipeCollectionPageSeoUrl.jsp" />
    4. Save the struts-extension.xml file.