Developing Web applications using the Web ADF  

Introduction to the Web ADF



The ArcGIS Server Java Platform provides a set of components that can be used to rapidly create a Web based mapping and analysis application. Not only do the components provide a broad array of functionality out of the box, but they have also been designed to allow for easy extension working with multiple data sources, such as ArcGIS Server and ArcIMS. The Web ADF controls and framework are JavaServer Faces (JSF) components for working with geographic data sources. By using the JSF framework, you can leverage an ecosystem of JSF components from ESRI and other vendors to quickly build highly interactive Web-based GIS applications.

This tutorial will start with a brief introduction to JSF, move on to creating a Web mapping application using the components that communicate with ArcGIS Server, ArcIMS, and then introduce other areas of the framework by extending this original application. After finishing this series of documents, you should be able to create custom applications using both out-of-the-box components that come with the Web ADF as well as your own custom GIS functionality.

JavaServer Faces

The following is from the JSF project home page:

JavaServer Faces technology simplifies building user interfaces for JavaServer applications. Developers of various skill levels can quickly build Web applications by: assembling reusable UI components in a page; connecting these components to an application data source; and wiring client-generated events to server-side event handlers.

JSF is a Java specification that defines a model for graphical user interface (GUI) components, an event-driven programming model, and a framework for producing applications that have a clean separation of presentation logic from application logic. For those familiar with desktop development in Java, you can think of JSF as Swing on the server.

 

Frameworks

JSF is built around a framework that insulates the application developer from many of the tedious details of creating Web applications. For example, in a servlet-based application, getting an integer parameter called NumberOfItems from a form into a Java class would require the following code:

	
	// Getting an integer from a servlet
	String numberOfItemsString = (String) request.getParameter("NumberOfItems");
	int numberOfItems = Integer.parseInt(numberOfItemsString);
	

As you will see with later examples, JSF simplifies the cumbersome parts of working with the Web tier.

 

More important, the framework underpinning JSF enables application developers to easily create applications that follow the Model-View-Controller (MVC) pattern. By using this pattern, developers create applications that cleanly separate business logic from presentation logic, thereby increasing application maintainability and flexibility. For a JSF application, the model consists of the business logic, which could be plain old Java Objects (POJOs) or EJBs. The view is provided by GUI components, which usually render HTML to the client's browser. The controller is a servlet interacting with numerous Java classes, allowing it to control interaction between the model and view tiers as well as overall application navigation. State of the application and requests are also handled by the framework, which allows for capabilities such as validation, providing messages to end users, and various other stateful functionality.

Configuration of the servlet and many other aspects of application are controlled through an XML file. Typically this file is, faces-config.xml, and it contains information on which Java classes will be managed through the framework (managed Beans), the name that JSP tags should use to refer to the Java classes (using JSF expression language), and the page flow logic for the application. For the ArcGIS components, this file plays a critical role in establishing the relationship between different components.

 

GUI components

The user interface components specified by JSF brings both standardization and flexibility to user interfaces in Java Web applications. These components concentrate on providing the view tier to the MVC architecture. As such, they only contain the properties and methods needed for rendering data from the model tier and accepting interaction from the end user. Application developers can rapidly wire components together, both from the same vendor as well as between different vendors, to create highly functional applications.

The type of output that a component generates is governed by its render kit, allowing the same components to generate XML, HTML, PDF, or other forms of output. JSF technology is designed to allow for the specification of different render kits during both application development and run time.

User interaction is also covered through the graphical components. The rendering of forms and the actions that occur when values are changed or buttons are pressed all derive from the components. The JSF standard also allows for the binding of validators to form elements, ensuring the quality of input data.

 

Business logic

Your business logic will be contained in Java classes. JSF is flexible in the way you create your classes in relation to your JSP pages. Some application developers create a single class for each page, which contains a property for an element on the form. These developers will then create a separate class to handle methods that are called when a user clicks a submit button or does a request to the server. Other developers include these in one class. And still other developers do some variation on this with the Beans acting as an intermediary layer to the real business objects underneath. For example, the method called with the submit button delegates calls to an EJB and, depending on the value returned from the EJB, returns different values to the controller. All the Java classes that interact with the controller and view tier are managed Beans, since they are managed by the JSF framework. Furthermore, the Beans that hold the values from the form are called backing Beans, since they can be thought of as backing a form.

There are several methods to allow JSPs to call methods in your Java classes. Much like Java Swing, the JSF architecture allows you to have events and listeners. In the case of JSF, events and listeners can be associated with an action, such as a button click; a value change, such as the user changing the text in a form element; or with a phase of the event-processing lifecycle. For your Java class to use these actions or listeners, it will have to implement a specific interface or inherit from a certain class. But you can also write a POJO with methods that return strings and use this in your framework. By using the JSF method binding expression language, you can call these methods and the string returned will tell the servlet which page is next in the application flow.

 

Further reading

This is only a brief introduction to the JSF framework. To understand the rest of the documentation for the ArcGIS JSF components, you will need a much deeper understanding of JSF. In particular, you will need to understand the faces-config.xml structure, the event model, the phases of a JSF request, managed and backing Beans, JSF expression language, and JSF JSP tags. If you are not familiar with these topics, here are some materials to get you started:

 

Online

The J2EE 1.4 tutorial from Sun contains extensive coverage on JSF.

Excadel has online tutorials on getting started with JSF.

Rick Hightower has authored an excellent series on JSF at DeveloperWorks.

The official JSF forums page is a great place to ask question about JSF development.

A JSF tutorials page contains a varied amount of information on JSF.

JSFCentral also has an excellent collection of JSF resources

Books

Kito Mann's JavaServer Faces in Action provides a good introduction to JSF, as well as covering some interesting use cases, such as JSF-Struts integration.

David Geary and Cay Horstmann's Core JavaServer Faces is a thorough coverage of the JSF framework.

 

Once you have a more complete understanding, you can move on to an overview of the Web ADF architecture.