Writing a JSP page


In this topic


Sample application JSP page

The JavaServer Pages (JSP) page in the Simple ArcGIS Server Web ADF Java platform application (the "sample application") is map.jsp. It is a relatively easy application, given that it displays a map and allows you to zoom in, out, and to full extent. There are important sections on the page that are described in this topic.

Tag declarations

The top of the page contains the tag declarations. In addition to the standard tag declarations for JavaServer Faces (JSF), there is a line for the Web Application Developer Framework (ADF). The following is an example.
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.esri.com/adf/web" prefix="a" %>
These are standard tag declarations in all the Web ADF templates and most of the samples. These declarations import the standard JSF tags, the JavaServer Pages Standard Tag Library (JSTL) core tags, and the Web ADF tags. A JSP tag on the page that begins with the letter "a" is referencing part of the Web ADF.

Web ADF tags

There are several Web ADF tags in map.jsp starting with the <f:view> tag, which is the parent tag to all JSF-specific tags. Because the view tag establishes the root node for the JSF view tree, all output managed by JSF must be in the view tag.
The next JSF tag is <h:form>, which is required to insert controls in an Hypertext Markup Language (HTML) form element. This tag allows the application to submit information back to the server. Any tag that posts information to the server, such as a tool, must be in a form tag.
Following the form tag is the <a:context> tag, which links the context control declared in faces-config.xml to this JSP page. The link between the view tier and model tier 1 occurs through the value binding of the context tag to the mapContext managed bean. The value binding of all the resources and model tier 1 objects associated with the context is now available on this page. It is possible to have multiple contexts on the same page; however, they would all need to be declared in faces-config.xml or, as with any JSF application, in multiple configuration files.

Commands and tools

The <a:toolbar> tag provides a container for the placement of tools and commands to use in the application. A toolbar is specified on only the JSP page; there are no declarations for a toolbar in faces-config.xml. You need to associate a toolbar with a map through the controlID attribute, and you can optionally set the activeTool.
A command is an element on a JSP page that triggers a server-side action without further interaction on the client. The example of a command in the sample application is the Zoom to Full Extent button. Once you click the button, a method is called on the server. A tool has further client-side interaction before calling a method on the server. An example of a tool in this application is Zoom to Rectangle. Once you click the button and drag a rectangle over the map indicating the area to zoom to, a method is called on the server. This interaction between map and tool is why a toolbar must specify its associated map.
The first two elements on the toolbar are the Zoom In and Zoom Out tools. There are two important attributes on these tags: clientAction and serverAction. The clientAction attribute specifies which JavaScript function is associated with the tool, and the serverAction attribute associates which class is called on the server when the client action is complete. When you click the Zoom In button, the browser executes a JavaScript function called MapDragRectangle. After you drag a rectangle over the map, the form submits to the server where the class ZoomInToolAction is called. The execute method is called on this class, and the output from the JavaScript is based on the methods as a MapEvent argument.
The next tag is a Web ADF command tag, which is used for pure server-side processing. The sample application uses the class ZoomFullExtentListener, which zooms the map to its full extent. The command tag is an extension of a JSF command tag that provides a richer user interface (UI) within the Web ADF. An actionListener is used because clicking the button calls into class Listener that is provided with the Web ADF. When you click the button for this command, the server-side action processAction is called on the class ZoomFullExtentListener.
The final Web ADF tag on the page is the map tag. This tag renders a map to the page, and its ID is used to identify it throughout the page, for example, with the toolbar. You can control certain properties of the map, such as size, drag box color for tools, border, and which Extensible Style Language (XSL) file to use, through the tag attributes. This map control is bound to webMap, which is a property of the context name mapContext using the value binding expression #{mapContext.webMap} for the value attribute. Therefore, this map will render any resources with a property for a map functionality and is also associated with mapContext.


See Also:

Configuring Web controls
How to add a command or tool
Creating a multisource Web ADF application