Web ADF Context Control


The ContextControl establishes a working environment for the GIS Server. Based on a specified value binding a connection to a GIS Server is established and maintained.  The ContextControl works with the WebContext object and the ContextTag class wraps the functionality of the ContextControl and enables the use of the context tag on a JSP page. 

Working with the WebContext

 
The WebContext maintains references to the GISResources as well as to attributes, GIS business objects, such as WebMap, WebGraphics, WebQuery, etc.  Additionally, the WebContext is responsible for making the callback methods implemented by the resources and attributes at appropriate junctures of the Web ADF application.  The callback methods are declared in the WebContextInitialize, WebContextObserver, and WebLifecyle interfaces. 
Users can add custom GIS business objects to the context as attributes of the WebContext programmatically as follows:
[Java]
WebContext cxt = mapControl.getWebMap().getWebContext();
MyAttribute myAttr = new MyAttribute();
cxt.setAttribute("myAttr", myAttr);
Users can also register attributes on the context in JSF managed bean configuration files as follows:
[XML]
<managed-bean>
  <managed-bean-name>myAttr</managed-bean-name>
  <managed-bean-class>myPackage.MyAttribute</managed-bean-class>
  <managed-bean-scope>none</managed-bean-scope>
</managed-bean>
<managed-bean>
  <managed-bean-name>myContext</managed-bean-name>
  <managed-bean-class>com.esri.adf.web.data.WebContext</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  ...
  <managed-property>
    <property-name>attributes</property-name>
    ...
    <map-entries>
      <map-entry>
        <key>myAttr</key>
        <value>#{myAttr}</value>
      </map-entry>
    </map-entries>
  </managed-property>
</managed-bean>
Once you have registered your object as an attribute of the context, the WebContext will make the appropriate callbacks into your object as it does with all attributes.  The WebContext also defines methods to dynamically add and remove GISResources from the context. 
[Java]
WebContext cxt = mapControl.getWebMap().getWebContext();
AGSMapResource ags = new AGSMapResource();
ags.setEndPointURL("http://myserver/mywebservice");
ags.addFunctionality("map", new AgsMapFunctionality());
cxt.addResource("ags1", ags, 0);
... ... cxt. removeResource(ags);
Users can work with multiple contexts in the same session.  All contexts are stored in a WebSession object which ensures that all WebContexts it maintains are cleanly destroyed when the user session terminates.