To add controls that change the site context, the first thing you must do is retrieve a list of the siteConfiguration
items to which you want to provide switching controls. This could be a list of all the sites in your application, or a list of the sites in a particular sharing group.
If you are rendering switching controls for all sites in your application, you can use the /atg/multisite/SiteManager
component. With the SiteManager
, you can retrieve siteConfiguration
items for all existing sites, all enabled sites or all active sites. The following examples show how.
To retrieve siteConfiguration
items for active sites:
<dsp:getvalueof var="activeSites"
bean="/atg/multisite/SiteManager.activeSites"/>
To retrieve siteConfiguration
items for enabled sites:
<dsp:getvalueof var="enabledSites"
bean="/atg/multisite/SiteManager.enabledSites"/>
To retrieve siteConfiguration
items for all sites:
<dsp:getvalueof var="allSites"
bean="/atg/multisite/SiteManager.allSites"/>
If you are rendering switching controls for the sites in a sharing group, use the /atg/dynamo/droplet/multisite/SharingSitesDroplet
instead. Depending on the input parameters you provide, this droplet returns all sites that are in a sharing group with the current site (or with a site other than the current one, if you provide a site ID). For example, you can return all sites that share a shopping cart with the current site. This droplet can be configured to exclude the current site from the list of returned siteConfiguration
items, allowing you to render controls that do not provide a link to the site the customer is currently viewing. You can also specify that only active sites are returned.
Note: If your Oracle ATG Web Commerce multisite application uses domains to determine site context, sharing session-scoped components will introduce the possibility of session hijacking for site visitors. A shared shopping cart is an example of a session-scoped component that will introduce this risk. When an application uses domains to determine site context, Oracle ATG Web Commerce must briefly include the session ID in site URLs. Oracle ATG Web Commerce has taken measures to reduce the risk of session hijacking posed by exposing the session ID. To eliminate the risk, do not use domains to determine site context.
After you have retrieved a list of siteConfiguration
items, you can render links to them. Commerce Reference Store uses the /atg/dynamo/droplet/multisite/SiteLinkDroplet
to build these links. This example shows how store.war/navigation/gadgets/sites.jsp
renders the Store portion of the Commerce Reference Store site picker. It uses the shopping cart sharing group to determine which sites links should be rendered for.
<dsp:page> <dsp:importbean bean="/atg/dynamo/droplet/multisite/SharingSitesDroplet"/> <dsp:importbean bean="/atg/dynamo/droplet/ForEach"/> <dsp:importbean bean="/atg/multisite/Site" var="currentSite"/> <%-- SharingSitesDroplet returns all the sharing sites within the given site group. If the siteId is not provided as an input parameter, it will be retrieved from the SiteContext. Similarly, the ShareableTypeId may be provided as an optional input parameter. The droplet is used here to return all the sites which have the atg.ShoppingCart sharable type with the current site, these are stores which share the same cart. --%> <dsp:droplet name="SharingSitesDroplet" shareableTypeId="atg.ShoppingCart" var="sharingSites"> <dsp:oparam name="output"> <%-- Ensure we have more than 1 site --%> <c:if test="${fn:length(sharingSites.sites) > 1}"> <dl id="atg_store_sites"> <dt> <%-- Display the Sites text --%> <fmt:message key="navigation_internationalStores.internationalStoresTitle"/> <fmt:message key="common.labelSeparator"/> </dt> <%-- ForEach droplet renders the open parameter output for each element in its array input parameter. For each site found render a link to the site. --%> <dsp:droplet name="ForEach" array="${sharingSites.sites}" sortProperties="-name" var="current"> <dsp:oparam name="output"> <dsp:setvalue param="site" value="${current.element}"/> <dsp:getvalueof var="siteName" param="site.name"/> <dsp:getvalueof var="siteId" param="site.id"/> <%-- Display a link to the other sites --%> <dd class="<crs:listClass count="${current.count}" size="${current.size}" selected="${siteId == currentSite.id}" />"> <c:choose> <%-- Display the current site name as text --%> <c:when test="${siteId == currentSite.id}"> <dsp:valueof value="${siteName}" /> </c:when> <%-- Otherwise generate a link to the site --%> <c:otherwise> <dsp:include page="/global/gadgets/crossSiteLinkGenerator.jsp"> <dsp:param name="siteId" value="${siteId}"/> <dsp:param name="customUrl" value="/"/> </dsp:include> <dsp:a href="${siteLinkUrl}" title="${siteName}"> <c:out value="${siteName}"/> </dsp:a> </c:otherwise> </c:choose> </dd> </dsp:oparam> </dsp:droplet> </dl> </c:if> </dsp:oparam> </dsp:droplet> </dsp:page>
Similar code renders the Country portion of the picker and can be found in store.war/navigation/gadgets/regions.jsp
. The regions.jsp
page uses the Related Regional Stores sharing group to identify the collection of sites that should be rendered next to the Country label. Note that because the country name requires translation, regions.jsp
retrieves it from a resource file, not from the site
object.
For more details on the SiteManager
component, see Configuring Site Types. For details on the SharingSitesDroplet
and SiteLinkDroplet
, see the ATG Page Developer's Guide.