Motorprise has different page sections such as Company Admin, Product Catalog, My Account, and Current Order. Each section contains different pages. When a user is browsing one of these sections, its title on the top navigation bar is highlighted.

In order to identify this location of the user and highlight the corresponding section title, we developed a servlet called SetCurrentLocation, an instance of the class atg.projects.b2bstore.servlet.WASetcurrentLocation, that is invoked during the request-handling pipeline.

We created a new transient property for the user, currentLocation, that stores the section he or she is accessing. The snippet below from /en/common/BrandNav.jsp shows how we check this property to highlight the appropriate section:

<dsp:droplet name="Switch">
  <dsp:param bean="Profile.currentLocation" name="value"/>
  <dsp:oparam name="admin">
    <td align="center"><dsp:a href="../admin/business_units.jsp">
    <b><font color="#FDD30E" size=-1>Company Admin</font></b></dsp:a></td>
  </dsp:oparam>
  <dsp:oparam name="default">
    <td align="center"><dsp:a href="../admin/business_units.jsp">
    <b><font color="#FFFFFF" size=-1>Company Admin</font></b></dsp:a></td>
  </dsp:oparam>
</dsp:droplet>

If the location is equal to admin, we highlight the Company Admin section of Motorprise in yellow as shown in the screenshot below.

SetCurrentLocation has a map property, relativePathMap, that specifies the mapping between URLs and virtual parts of the store, using URLs relative to the web application context root. It converts these to absolute URLs at runtime. This property contains the relative document paths for each section (Company Admin, Product Catalog, My Account, and Current Order) and the value to be set in the location property if the user accesses any page from one of those paths. This is the properties file for MotorpriseJSP/j2ee-apps/Motorprise/config/atg/projects/b2bstore/servlet/SetCurrentLocation:

$class=atg.projects.b2bstore.servlet.WASetCurrentLocation

# Specify where in the servlet pipeline this servlet should appear
insertAfterServlet=/atg/userprofiling/ProfileRequestServlet

# Specify the web application registry where Motorprise is registered
webAppRegistry=/atg/registry/webappregistry/ServletContextWebAppRegistry

# Specify the name under which the Motorprise web app is registered
webApplicationName=MotorpriseJSP

# Set URL's relative to the Motorprise context root.

relativePathMap=/en/catalog/=product_catalog,\
            /en/admin/=admin,\
            /en/home.jsp=product_catalog,\
            /en/checkout/=current_order,\
            /en/user/=my_account,\
            /de/catalog/=product_catalog,\
            /de/admin/=admin,\
            /de/home.jsp=product_catalog,\
            /de/checkout/=current_order,\
            /de/user/=my_account,\
            /ja/catalog/=product_catalog,\
            /ja/admin/=admin,\
            /ja/home.jsp=product_catalog,\
            /ja/checkout/=current_order,\
            /ja/user/=my_account

When the user requests a new page, the URL is compared to the paths in the relativePathMap property. The servlet sorts the keys of the map, which are document paths, in ascending order, and checks whether the directory path exists in the request. If there is an exact match, then the corresponding value is assigned to the location property. If there is not an exact match, the closest directory to which the URL belongs is found and the value of that directory is added to location.

 
loading table of contents...