Updating view names in the Struts configuration file

In this tutorial, you update TopDisplayCatagoriesView as an example on how to update the struts configuration file to use a common view across each storefront.

Before you begin

Before you begin:

  • Note the internal IDs defined in your wc-devices.xml file.
  • Note your store ID.

About this task

Update the Struts configuration file (struts-config-ext.xml) to use a common view across each storefront. In this lesson, you use TopCategoriesDisplayView as an example. In the file, there are variants of the view name. The m20TopCategoriesDisplayView corresponds to the smartphone, and tTopCategoriesDisplayView corresponds to the tablet starter stores. In this lesson, you map a single view name to the corresponding JSP file for the desktop, smartphone, and tablet starter stores with device IDs defined in wc-devices.xml.
Note: A 1:1 mapping between pages across each storefront is essential for redirection to work consistently. For a particular JSP that exists in one storefront, there also exists a JSP that renders the same content in other storefronts. Similarly, the view that maps to the JSP for one storefront also maps to the equivalent JSP in the other storefront. If this is not true, a URL might redirect users to pages with different content when viewed from different devices.

For example, in the default configuration, each storefront has a StoreView action mapping that serves as the storefront home page. For desktop and tablet stores, this view is mapped to index.jsp, which redirects users to TopCategoriesDisplayView and its corresponding TopCategoriesDisplay.jsp. This page serves as the home page and provides access to the category menu. The smaller smartphone form factor results in a separation of the home page from the category page which requires the use of two separate views. SEO patterns are required to be unique and cannot map to more than one view. Therefore, for this tutorial, redirection from a desktop or tablet home page to a smartphone storefront directs the user to the smartphone TopCategoriesDisplayView rather than the StoreView. You learn how to set the redirection in this tutorial by updating the corresponding SEO patterns. The default smartphone home page remains accessible directly by URL.

Procedure

The examples in this lesson use a sample store ID of 10001, use your store ID in place of 10001 where applicable. Similarly, the lesson examples use internal ID for tablet devices is -31 and smartphone devices is -21, as defined in the wc-devices.xml file. Replace -31 with the internal ID for your tablet device and -21 with the internal ID for smartphone device.

Struts configuration changes to support redirection of the TopCategoriesDisplayView.

  1. Go to Stores > WebContent > WEB-INF and open struts-config-ext.xml. Switch to Source view.
  2. In the <action-mappings> section, locate the action with path="/TopCategoriesDisplayView". It resembles the following code snippet:
    <action path="/TopCategoriesDisplayView" type="com.ibm.commerce.struts.BaseAction">
    <set-property property="credentialsAccepted" value="10101:P,10701:P,10751:P"/>
    </action>
    The <set-property> elements might differ from the values that are found in yourstruts-config-ext.xml file.

    If your Struts configuration file does not contain this action element, create the action entry, substituting your store ID for the property value. If you added new actions and views, you might need to create/update the access control policies for those views.

  3. In the <global-forwards> section, locate the forward elements with name="TopCategoriesDisplayView". If you have more than one published store, there might be several instances of forward elements with the different store IDs as part of the name. Select the element with the store ID corresponding to your store.
    1. Locate the <forward> element corresponding to tTopCategoriesDisplayView:
      <forward className="com.ibm.commerce.struts.ECActionForward" 
      name="tTopCategoriesDisplayView/10001" 
      path="/tablet/ShoppingArea/CatalogSection/CategorySubsection/TopCategoriesDisplay.jsp"/>

      The t prefix in the view name and tablet in the path attribute indicates this TopCategoriesDisplayView corresponds to tablet devices.

    2. Update the name attribute by removing the prefix t from TopCategoriesDisplayView and append the internal ID to the name, which is preceded by a forward slash (/). The updated line resembles the following code:
      <forward className="com.ibm.commerce.struts.ECActionForward" 
      name="TopCategoriesDisplayView/10001/-31" 
      path="/tablet/ShoppingArea/CatalogSection/CategorySubsection/TopCategoriesDisplay.jsp"/>
    3. Locate the <forward> element corresponding to m20TopCategoriesDisplayView:
      <forward className="com.ibm.commerce.struts.ECActionForward" 
      name="m20TopCategoriesDisplayView/10001" 
      path="/mobile20/ShoppingArea/CatalogSection/CategorySubsection/TopCategoriesDisplay.jsp">
      </forward>
    4. Update the name attribute by removing the prefix m20 and appending the internal ID, similar to the previous change:
      <forward className="com.ibm.commerce.struts.ECActionForward" 
      name="TopCategoriesDisplayView/10001/-21" 
      path="/mobile20/ShoppingArea/CatalogSection/CategorySubsection/TopCategoriesDisplay.jsp">
      </forward>
  4. Save the file. Keep the file open for the next steps.
After you complete these steps, you have a defined action for TopCategoriesDisplayView. This view name is common to each storefront desktop browser, smartphone, and tablet devices, and differentiated by the device ID.

Struts configuration changes to support redirection of the category-related views.

  1. Go to Stores > WebContent > WEB-INF and open struts-config-ext.xml. Switch to Source view.
  2. In the <global-forwards> section, locate the following code block:
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericDepartmentPageLayoutView/10001" 
    path="/Layouts/TopCategoryPage.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericCategoryPageLayoutView/10001" 
    path="/Layouts/CategoryNavigationDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericSubCategoryPageLayoutView/10001" 
    path="/Layouts/SubCategoryPage.jsp"/>

    Replace with the following code snippet. Substitute 10001 with your store ID, -21 with your internal ID defined for smartphone devices, and -31 with your internal ID defined for tablet devices. This code snippet adds more <forward> elements for each of the views in the preceding example, specific for the smartphone and tablet devices.

    <forward className="com.ibm.commerce.struts.ECActionForward" name="GenericDepartmentPageLayoutView/10001" 
    path="/Layouts/TopCategoryPage.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" name="GenericCategoryPageLayoutView/10001" 
    path="/Layouts/CategoryNavigationDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" name="GenericSubCategoryPageLayoutView/10001" 
    path="/Layouts/SubCategoryPage.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" name="GenericDepartmentPageLayoutView/10001/-21" 
    path="/mobile20/ShoppingArea/CatalogSection/CategorySubsection/CategoriesDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" name="GenericCategoryPageLayoutView/10001/-21" 
    path="/mobile20/ShoppingArea/CatalogSection/CategorySubsection/CategoriesDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" name="GenericDepartmentPageLayoutView/10001/-31" 
    path="/tablet/ShoppingArea/CatalogSection/CategorySubsection/CategoriesDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" name="GenericCategoryPageLayoutView/10001/-31" 
    path="/tablet/ShoppingArea/CatalogSection/CategorySubsection/CategoriesDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" name="GenericSubCategoryPageLayoutView/10001/-21" 
    path="/mobile20/ShoppingArea/CatalogSection/CategorySubsection/CategoriesDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" name="GenericSubCategoryPageLayoutView/10001/-31" 
    path="/tablet/ShoppingArea/CatalogSection/CategorySubsection/CategoriesDisplay.jsp"/>
  3. Save and close the file.

Struts configuration changes to support redirection of the product-related views.

  1. Go to Stores > WebContent > WEB-INF and open struts-config-ext.xml. Switch to Source view.
  2. In the <global-forwards> section, locate the following code block:
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericProductPageLayoutView/10001" path="/Layouts/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericBundlePageLayoutView/10001" path="/Layouts/BundleDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericItemPageLayoutView/10001" path="/Layouts/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericStaticKitPageLayoutView/10001" path="/Layouts/PackageDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericDynamicKitPageLayoutView/10001" path="/Layouts/DynamicKitDisplay.jsp/>

    Replace with the following code snippet. Substitute 10001 with your store ID, -21 with your internal ID defined for smartphone devices, and -31 with your internal ID defined for tablet devices:

    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericProductPageLayoutView/10001" 
    path="/Layouts/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericProductPageLayoutView/10001/-21" 
    path="/mobile20/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericProductPageLayoutView/10001/-31" 
    path="/tablet/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericBundlePageLayoutView/10001" 
    path="/Layouts/BundleDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericBundlePageLayoutView/10001/-21" 
    path="/mobile20/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericBundlePageLayoutView/10001/-31" 
    path="/tablet/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericItemPageLayoutView/10001" 
    path="/Layouts/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericItemPageLayoutView/10001/-21" path="/mobile20/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericItemPageLayoutView/10001/-31" path="/tablet/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericStaticKitPageLayoutView/10001" path="/Layouts/PackageDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericStaticKitPageLayoutView/10001/-21" path="/mobile20/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericStaticKitPageLayoutView/10001/-31" path="/tablet/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericDynamicKitPageLayoutView/10001" path="/Layouts/DynamicKitDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericDynamicKitPageLayoutView/10001/-21" path="/mobile20/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
    <forward className="com.ibm.commerce.struts.ECActionForward" 
    name="GenericDynamicKitPageLayoutView/10001/-31" path="/tablet/ShoppingArea/CatalogSection/CatalogEntrySubsection/ProductDisplay.jsp"/>
  3. Save and close the file.
  4. Restart the server.