Getting started with Java ADF development-Simple ArcGIS Server Web ADF Application __java

Source: Internet
Author: User
Create a Web Map application project

1. Create a new ArcGIS server project. Select File>new>project from the Eclipse main menu, navigate to Esri Templates>server, and select ArcGIS Server Project. Click Next.

2. Enter Agssimple as the project name and select a Web container from Target runtime.

3. Enter the correct GIS server name, username, password and domain. Click the Connect button to see that the server objects appears in the bottom left list. Click to select the USA service created earlier. Click Finish to generate a map Web application.

The Eclipse IDE uses templates to generate a relatively complex map Web application for us. For this example, we do not need too complex functionality, so as long as two files: Web-inf directory under the Faces-config.xml and WEB application root directory of map.jsp. Faces-config.xml files are business objects that are used to connect to the Web ADF framework framework, exposing these objects to the view/web layer, specifying the appropriate GIS servers for the application, and providing authentication information. MAP.JSP contains JSP tags for rendering map applications, such as maps, tables of contents (TOC), and map tools. The data that is used to create these views is, in turn, bound to the data source specified by Faces-config.xml.

Web Controls and Managed-bean

Several Web controls are used in Web ADF applications, some are visible, such as the map and tools Web controls, and some are not visible, such as context control. These controls must be configured in the Web ADF application before they are used. Web control configuration involves several files:
Context-attributes.xml
Ags-functionalities.xml
Face-config.xml
Context-attributes.xml: In Context-attributes.xml, you create a managed-bean named map, which is a logical representation of the maps Web controls you see in the same application. After this managed-bean is created, you also need to set some properties for it. For example, you can set a map Managed-bean "ImageFormat" attribute to "PNG".

Context-attributes.xml:

<managed-bean>
<managed-bean-name>map</managed-bean-name>
<managed-bean-class>com.esri.adf.web.data.WebMap</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
<managed-property>
<property-name>imageFormat</property-name>
<value>PNG</value>
</managed-property>
</managed-bean>

This simple application has only one map control, so the managed-bean of only one map control needs to be created. If you need to add controls like "Toc" and "Overview", you will also create these anaged-beans in Context-attributes.xml.

Ags-functionalities.xml: In Ags-functionalities.xml, you created Managed-beans for the different features of the ArcGIS server:
Agsmap: A managed-bean that represents the map function of the maps control
Agstoc: A managed-bean that represents the TOC function of a TOC control
Agsoverview: A managed-bean that represents the overview function of a overview control

Ags-functionalities.xml:
<managed-bean>
<managed-bean-name>agsMap</managed-bean-name>
<managed-bean-class>com.esri.adf.web.ags.data.AGSMapFunctionality</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
</managed-bean>

<managed-bean>
<managed-bean-name>agsToc</managed-bean-name>
<managed-bean-class>com.esri.adf.web.ags.data.AGSTocFunctionality</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>agsOverview</managed-bean-name>
<managed-bean-class>com.esri.adf.web.ags.data.AGSOverviewFunctionality</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
</managed-bean>
Once a functionality Managed-bean is created and added to the resource Managed-bean properties, it can be used in web ADF applications. In this example, only the map functionality is added as a property of the map resource. More functionalitie, like query, GeoCode, and history can be created and added to the map resource.

Faces-config.xml: In Faces-config.xml, four managed beans are defined: "Esriwebapplication", "Esriwebsession", "AGS1", "Mapcontext" .
"AGS1" represents the GIS data source you want to publish in your Web application. In this case, ArcGIS Server. Defined in the Ags-functionalities.xml functionality add to the list of properties in the map resource.
"Esriwebapplication" is always set to application level Managed-bean in the ADF Web application.
"Esriwebsession" The Managed-bean holds "esriwebapplication" as the attribute.
The "Mapcontext" Managed-bean is the logical representation of the "context" control and holds "esriwebsession" and "map" as its properties.
For any web ADF application, the latter three managed-bean are necessary, especially "Mapcontext", which connects and coordinates other ADF components like a hub. This is also a "map" as its property and "AGS1" as its resource.
Faces-config.xml:

<managed-bean>
<managed-bean-name>esriWebApplication</managed-bean-name>
<managed-bean-class>com.esri.adf.web.data.WebApplication</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>esriWebSession</managed-bean-name>
<managed-bean-class>com.esri.adf.web.data.WebSession</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>webApplication</property-name>
<value>#{esriWebApplication}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>mapContext</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>webSession</property-name>
<value>#{esriWebSession}</value>
</managed-property>
<managed-property>
<property-name>attributes</property-name>
<map-entries>
<map-entry>
<key>map</key>
<value>#{map}</value>
</map-entry>
</map-entries>
</managed-property>
<managed-property>
<property-name>resources</property-name>
<map-entries>
<map-entry>
<key>ags1</key>
<value>#{ags1}</value>
</map-entry>
</map-entries>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>ags1</managed-bean-name>
<managed-bean-class>com.esri.adf.web.ags.data.AGSMapResource</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
<managed-property>
<property-name>user</property-name>
<value>#{agsUser1}</value>
</managed-property>
<managed-property>
<property-name>serverObjectName</property-name>
<value>usa</value>
</managed-property>
<managed-property>
<property-name>hosts</property-name>
<list-entries>
<value>YourServer</value>
</list-entries>
</managed-property>
<managed-property>
<property-name>functionalities</property-name>
<map-entries>
<map-entry>
<key>map</key>
<value>#{agsMap}</value>
</map-entry>
<map-entry>
<key>overview</key>
<value>#{agsOverview}</value>
</map-entry>
</map-entries>
</managed-property>
</managed-bean>
Once these managed-bean are properly configured in Context-attribute.xml,ags-functionalities.xml and Faces-config.xml, you can easily in the ADF Add Web controls as JSP tags in JSP pages for Web applications.

Writing JSP pages

This example has only one page map.jsp. The page is relatively simple: it only shows a map that allows the user to zoom in, zoom out, and zoom in.

Commands and tools

<a:toolbar> tags provide containers for applied tools and commands. The toolbar is only specified on the JSP page and there is no toolbar declaration in the Faces-config.xml. You must use the control's ID to associate the toolbar and the map, and you can optionally set the current tool.

A command is a JSP page element that triggers a service-side action without requiring further client interaction. An example of a command is the "Zoom to All" button. When the user hits the button, the server executes a method. The tool requires further client interaction before executing a service-side method. An example of a tool is "box selection amplification." The user will click the button and drag a box on the map to indicate the area you want to enlarge, and then the service-side method is executed. The interaction of maps and tools is the reason for the toolbar to specify its associated map.

The first two elements of the toolbar are magnified and scaled down. These two tags have two important attributes: Clientaction and Serveraction. The Clientaction property specifies which JavaScript function is associated with the tool, and the Serveraction property specifies which class of the server is invoked when the client action ends. For the first tool. When the user clicks the Zoom in button, the browser executes a JavaScript function called Mapdragrectangle. After the user draws a box on the map Map0, the form is submitted to the server, and the server invokes the Zoomintoolaction class. The execution method of this class is invoked, and the output of JavaScript is used as the Mapevent parameter of the method.

The next label is the command label, which is used for pure service-side processing. This example uses a zoomfullextentlistener to enlarge the map to the full. The command label is an extension of the JSF command label. When the user clicks on the command button, the server invokes the Zoomfullextentlistener class's Processaction method.

The last Web ADF tag is a map label that renders a map on the page, and its ID is used to identify the map in the page, such as its association with the toolbar. You can control the properties of some maps by tag properties, such as size, toolbar color, borders, and which XSL to use.

Summary

Diagram of the Managed-bean between the ADF:

Mapcontext (Webcontext)
|
+esriwebsession (websession)
| |
| +esriwebapplication (WebApplication)
|
+attributes
| |
| +map (WebMap)
| +toc (WEBTOC)
| +...
|
+resources
|
+AGS1 (Agsmapresource)
|
+agsuser1
|
+serverobjectname
|
+hosts
|
+functionalities
|
+agsmap (agsmapfunctionality)
+agstoc (agstocfunctionality)
+agsoverview (agsoverviewfunctionality)
+...

To create a map Web application:

1. Declare the MapServer object of the ArcGIS server as a Gisresource
2. Associate Agsmapfunctionality and Gisresource
3. Declare WebMap to use functionality
4. Associate WebMap and context to ensure that it participates in the Web ADF framework
5. Write the appropriate JSP tags on the JSP page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.