In a multisite environment, it might be desirable to provide access to another site while handling the current site’s request. For example, selection of a given product might trigger display of related products from another site. You can allow users to retrieve additional product information from that site by temporarily switching the current page’s site context.

A page can switch site context through the servlet bean SiteContextDroplet. This servlet bean resets the site context as directed by the supplied site ID, and its output parameter acts as a wrapper for the new site context. Before the output parameter executes, the SiteContextManager uses the site ID to push a new SiteContext object onto the SiteContext stack and establish it as the new site context.

The changed site context remains in effect until SiteContextDroplet exits; the SiteContextManager then pops the site context off the stack and restores the previous site context to the page. For detailed information about site context, see the ATG Platform Programming Guide.

Empty Site Context

You can use SiteContextDroplet to set an empty site context by setting the input parameter emptySite to true. For the duration of output parameter execution, the page’s site context is empty and the page has access to repository data of all sites.

If desired, you can set an empty site context for an entire page by wrapping it entirely inside SiteContextDroplet’s output parameter and setting emptySite to true.

SiteContextDroplet Example

The following page code uses SiteContextDroplet to change the site context to site1. It then invokes the servlet bean TargetingFirst within the SiteContextDroplet output parameter:

<%@ taglib uri="http://www.atg.com/taglibs/daf/dspjspTaglib1_0" prefix="dsp" %>
<dsp:importbean bean="/atg/dynamo/droplet/multisite/SiteContextDroplet"/>
<dsp:importbean bean="/atg/targeting/TargetingFirst"/>

<dsp:page>
<html>
<body>

<dsp:droplet name="SiteContextDroplet">
  <dsp:param name="siteId" param="site1"/>
  <dsp:oparam name="output">
    <dsp:droplet name="TargetingFirst">
      <dsp:param name="targeter" bean="/atg/multisite/SiteTargeter"/>
      <dsp:oparam name="output">
        <img src="<dsp:valueof param='element.url'/>"/><BR/>
      </dsp:oparam>
      <dsp:oparam name="empty">
          No content returned from the Targeter<BR/>
      </dsp:oparam>
    </dsp:droplet>
  </dsp:oparam>
  <dsp:oparam name="error">
     Unable to set site context. Error:&nbsp;
     <dsp:valueof param="errorMessage"/>
  </dsp:oparam>
</dsp:droplet>

</body>
</html>
</dsp:page>

Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved.

Legal Notices