Adding Store specific controllers and views

Customize or extend your existing Spring MVC configuration within the custom stores web archive. A step by step guide is provided to configuring store level controllers and views.

About this task

When you access to a store page (or execute a controller action), remote store foundation will try to find the mapping between the current dynamic URL (All SEO URL will be parsed into a dynamic URL like this https://hostname:8443/wcs/shop/TopCategoriesDisplay?catalogId=10502&storeId=1&langId=-1) and view bean( definition of a JSP page ). I will follow the following rule to find the view bean.
  1. Find the store level view bean definition by name TopCategoriesDisplay/<CurrentEsiteStoreIdentifer>. Render this page if get the view bean. Otherwise go to step #2).
    Note: If you want to use this esite level view configuration, you should put your JSP page in the corresponding asset store’s directory.Another way is to configure a full path of JSP relative to WebContent folder and add property storeDire=no. Here is the configuration sample.
    <bean id="TopCategoriesDisplay/Auroraesite" class="com.ibm.commerce.store.mvc.view.spring.StoreInternalResourceView"> 
        <property name="url" value="/<Auroraesite or any name>/ShoppingArea/CatalogSection/CategorySubsection/MyTopCategoriesDisplay.jsp"/>  
        <property name="https" value="1"/>  
        <property name="credentialsAccepted" value="P"/> 
        <property name="generic" value="1"/>
    <property name="storeDir" value="no"/>
      </bean>
    
  2. Find the store view bean definition by name TopCategoriesDisplay/<CurrentAssetStoreIdentifer>. Render this page if get the view bean. Otherwise go to step #3.
  3. Find the site level view bean definition by name TopCategoriesDisplay. Render this page if get the view bean. Otherwise go to step #4).
  4. Go to view not found error page.

Procedure

  1. Site level controllers are saved in crs-web\WebContent\WEB-INF\spring\controllers.xml and all controllers are shared cross all stores.You also can define a store specific controllers in controlllers-ext.xml file and include it in the bottom of controllers.xml.
    The contents of crs-web\WebContent\WEB-INF\spring\controllers.xml will look something like the following:
    <import resource=”classpath:/WEB-INF/spring/AuroraStorefrontAssetStore/controllers-ext.xml”/>
    <import resource=”classpath:/WEB-INF/Spring/AuroraStoreB2BfrontAssetStore/controllers-ext.xml”/>
    <import resource=”classpath:/WEB-INF/spring/<your Store Directory Name>/controllers-ext.xml”/>
    
          <prop key=”/AjaxRESTUpdateMarketingTrackingConsent”>ajaxRESTUpdateMarketingTrackingConsent</prop>
        </props>
      </property>
    </bean>
    <bean class=”com.ibm.commerce.store.mvc.registry.spring.StoreUrlHandlerMapping” id=”viewUrlmapping”>
    …
      <property name=”order” value=”3”/>
    …
      <property name=”mappings”>
        <props>
    …
          <prop key=”/CategoryDisplay”>browsingController</prop>
          <prop key=”/TopCategoriesDisplay”>browsingController</prop>
          <prop key=”*”>viewController</prop>
       </props>
    </property>
    </bean>
    <import resource=”classpath:/WEB-INF/spring/AuroraStorefrontAssetStore/controllers-ext.xml”/>
    <import resource=”classpath:/WEB-INF/Spring/AuroraStoreB2BfrontAssetStore/controllers-ext.xml”/>
    <import resource=”classpath:/WEB-INF/spring/<your Store Directory Name>/controllers-ext.xml”/>
    
  2. 2. Change the controllers-ext.xml file on demand ( /crs-web/WebContent/WEB-INF/spring/<StoreDirectoryName>/controllers-ext.xml) according to the reference file (WEB-INF/spring/AuroraB2BStorefrontAssetStore/controllers-b2b-delta-template.xml or WEB-INF/spring/AuroraStorefrontAssetStore/controllers-b2c-delta-template.xml). The file will be created during store publish process and the @STORE_IDENTIFIER@ variable will replaced with store identifier. You also can define your own controller according to the pattern.
    <bean id="actionUrlmapping-@STORE_IDENTIFIER@" class="com.ibm.commerce.store.mvc.registry.spring.StoreUrlHandlerMapping"> 
        <property name="order" value="0"/>  
        <property name="mappings"> 
          <props> 
          	<!-- B2B delta controller config -->
            <prop key="/RESTOrderCalculate/@STORE_IDENTIFIER@">orderCalculate/@STORE_IDENTIFIER@</prop>  
            <prop key="/AjaxRESTOrderCalculate/@STORE_IDENTIFIER@">AjaxRESTOrderCalculate/@STORE_IDENTIFIER@</prop>  
            <prop key="/AjaxRESTOrderItemAdd/@STORE_IDENTIFIER@">ajaxOrderItemAdd/@STORE_IDENTIFIER@</prop>  
            <prop key="/RESTOrderItemAdd/@STORE_IDENTIFIER@">ajaxOrderItemAdd/@STORE_IDENTIFIER@</prop>
            <!-- Add customer controller url mappings here -->    
          </props> 
        </property> 
      </bean>  
      <bean id="viewUrlmapping-@STORE_IDENTIFIER@" class="com.ibm.commerce.store.mvc.registry.spring.StoreUrlHandlerMapping"> 
        <property name="order" value="2"/>  
        <property name="mappings"> 
          <props> 
          </props> 
        </property> 
      </bean> 
      <!-- B2B delta controller config -->
      <bean id="orderCalculate/@STORE_IDENTIFIER@" class="com.ibm.commerce.store.mvc.controller.spring.RESTActionController"> 
        <property name="authenticate" value="1"/>  
        <property name="https" value="1"/>  
        <property name="parameter" value="orderlist.calculateOrder"/> 
      </bean>  
      <bean id="AjaxRESTOrderCalculate/@STORE_IDENTIFIER@" class="com.ibm.commerce.store.mvc.controller.spring.AjaxRESTActionController"> 
        <property name="authenticate" value="1"/>  
        <property name="https" value="1"/>  
        <property name="parameter" value="orderlist.calculateOrder"/> 
      </bean>  
      <bean id="ajaxOrderItemAdd/@STORE_IDENTIFIER@" class="com.ibm.commerce.store.mvc.controller.spring.AjaxRESTActionController"> 
        <property name="authenticate" value="1"/>
        <property name="parameter" value="orderlist.addOrderItem"/>  
        <property name="https" value="1"/> 
      </bean>   
      <!-- Add customer controller bean definitions here -->       
    </beans>
    
  3. Site level view beans (map to JSP) are saved in crs-web\WebContent\WEB-INF\spring\views.xml and all views are shared across all stores. You also can create store-specific view beans and put them in crs-web\WebContent\WEB-INF\spring\StoreDirectoryName\views-ext.xml file. But you need to include the views-ext.xml in crs-web\WebContent\WEB-INF\spring\views.xml
    <import resource=”classpath:/WEB-INF/spring/AuroraStorefrontAssetStore/views-ext.xml”/>
    <import resource=”classpath:/WEB-INF/spring/AuroraB2BStorefrontAssetStore/views-ext.xml”/>
    <import resource=”classpath:/WEB-INF/spring/Your Store Directory Name/views-ext.xml”/>
    
  4. Change the crs-web\WebContent\WEB-INF\spring\<StoreDirectoryName>\views-ext.xml file on demand according the reference files (/crs-web/WebContent/WEB-INF/spring/AuroraB2BStorefrontAssetStore/views-b2b-delta-template.xml or /crs-web/WebContent/WEB-INF/spring/AuroraStorefrontAssetStore/views-b2c-delta-template.xml). You need to replace the variable @STORE_IDENTIFIER@ to your store identifier.
      <!-- B2B delta view config -->
      <bean id="QuickOrderView/@STORE_IDENTIFIER@" class="com.ibm.commerce.store.mvc.view.spring.StoreInternalResourceView"> 
        <property name="url" value="/ShoppingArea/OrderCreationSection/QuickOrderSubsection/QuickOrderForm.jsp"/>  
        <property name="credentialsAccepted" value="P"/>  
        <property name="authenticate" value="1"/> 
      </bean>
      <bean id="AjaxOrderItemDisplayView/@STORE_IDENTIFIER@" class="com.ibm.commerce.store.mvc.view.spring.StoreInternalResourceView"> 
        <property name="url" value="/ShoppingArea/ShopcartSection/OrderItemDisplay.jsp"/>  
        <property name="https" value="1"/>  
        <property name="credentialsAccepted" value="P"/>  
        <property name="authenticate" value="1"/> 
        <property name="generic" value="1"/>
      </bean>
      <!-- Special bean for B2B store to use https for all pages. This is necessary for organization and contract to be displayed correctly in header. -->  
      <bean id="HttpsRequiredForAllViews/@STORE_IDENTIFIER@" class="com.ibm.commerce.store.mvc.view.spring.StoreInternalResourceView">  
        <property name="https" value="1"/>  
        <property name="url" value=""/>
      </bean>