Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

2 - Adding a URL mapping and Simple Page Controller

2 - Adding a URL mapping and Simple Page Controller

After creating the Privacy Policy page, your Storefront needs to know the page's location and the URL that will request the page. To configure the storefront with the page's location and URL, you will modify the Storefront extension project (found in <Source Code Root>/extensions/storefront/ext-storefront). The Storefront extension project is where all your Storefront customizations will live. By having your customizations in an extension project, separate from the out of the box code, you receive the benefits of binary based development.

Adding the URL Mapping and Page Controller

To specify the Privacy Policy page's location and the URL that will request the page, you need to do two things:

  • In your storefront extension, create a Java Bean definition that calls the Simple Page Controller, an out of the box Storefront class responsible for loading static HTML pages.
  • Add the page's URL to the URL Handler Mapping bean, which maps URLs to controller bean definitions.

To load the Privacy Policy page into the Storefront and map the page to the /privacy.ep URL:

  1. In the /ext-storefront/src/main/resources folder, create a spring/web subdirectory.In the web directory, create an XML file named url-mapping.xml and insert the following XML code:
                      CoreTutorial1/tutorial1-ext-storefront/src/main/resources/spring/web/url-mapping.xml
    <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-3.0.xsd">
    
    	<bean id="privacyController"
    		  class="com.elasticpath.sfweb.controller.impl.SimplePageControllerImpl"
    		  parent="abstractEpController">
    		<property name="viewName">
    			<value>static/privacy</value>
    		</property>
    	</bean>
    
    	<bean id="SimpleUrlHandlerMapping"
    		  class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"
    		  parent="AbstractSimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props merge="true">
    				<prop key="/commerce-legacy/privacy.ep">privacyController</prop>
    			</props>
    		</property>
    	</bean>
    </beans>
    
                   
    This defines a SimplePageController bean that handles loading of the privacy policy page and a SimpleUrlHandlerMapping bean that maps the privacy policy page to the /privacy.ep URL.
  2. In ext-storefront/src/main/resources/META-INF/conf/ep-storefront-plugin.xml, add the following XML code under the <beans> tag:
                      CoreTutorial1/tutorial1-ext-storefront/src/main/resources/META-INF/conf/ep-storefront-plugin.xml
    	<import resource="classpath*:spring/web/url-mapping.xml"/commerce-legacy/>
    
                   
    This imports url-mapping.xml into the Storefront Extension project.