In this topic
About the ContextControl
The ContextControl Web Application Developer Framework (ADF) control establishes a working environment for the geographic information system (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, wrapping the functionality of the ContextControl and enabling the use of the context tag on a JavaServer Pages (JSP) page. See the following diagram:
Working with the WebContext
The WebContext maintains references to GISResources as well as to attributes and GIS business objects, such as WebMap, WebGraphics, WebQuery, and so on. 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.
You can add custom GIS business objects to the context as attributes of the WebContext programmatically as shown in the following code example:
[Java]
WebContext cxt = mapControl.getWebMap().getWebContext();
MyAttribute myAttr = new MyAttribute();
cxt.setAttribute("myAttr", myAttr);
You can also register attributes on the context in JavaServer Faces (JSF) managed bean configuration files as shown in the following code example:
[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've registered your object as an attribute of the context, the WebContext makes 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. See the following code example:
[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);
You 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 removed when the session is terminated.