<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-12321538</id><updated>2012-01-26T08:28:31.771-08:00</updated><title type='text'>Geo Coding</title><subtitle type='html'>My 2 cents on GIS programming</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-12321538.post-113046134860946381</id><published>2005-10-27T18:00:00.000-07:00</published><updated>2005-10-28T11:01:21.136-07:00</updated><title type='text'>Adding Selection tool to MapViewer template</title><content type='html'>Although the selection tool is provided in ArcGIS Server MapViewer template, it can't be used as-is unlike other tools (zoomin, identify etc.) That is because it is necessary to set the selected layer to the AGSSelection object before this tool can be used. &lt;br /&gt;&lt;div style='background-color:whitesmoke;width:300px;font-family:courier;border:solid 2px #CCCCCC;'&gt;&lt;pre style='padding:0px;margin:0px;'&gt;&lt;br /&gt;AGSSelection selection = (AGSSelection)&lt;br /&gt;  agsContext.getAttribute(&lt;br /&gt;   AGSSelection.WEB_CONTEXT_ATTRIBUTE_NAME);&lt;br /&gt;selection.setSelectedLayerId(layerId);&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Here are the steps to implement the selection tool in the MapViewer template:&lt;br /&gt;&lt;br /&gt;1. Use arcgisant tool to create a web application named SelectionTest using the MapViewer template. &lt;br /&gt;&lt;br /&gt;2. Create a new project as discussed &lt;a href="http://kafle.blogspot.com/2005/10/ant-tool-for-customizing-arcgis-server.html"&gt;here&lt;/a&gt; and copy over the newly created webapplication from ArcGIS build directory to this directory. Be sure to update the build file with the new app name.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. Under the src folder, create a folder named test.&lt;br /&gt;&lt;br /&gt;4. Create a file named AGSSelectionLayer.java in the test folder with this content:&lt;br /&gt;&lt;div style='background-color:whitesmoke;width:300px;font-family:courier;border:solid 2px #CCCCCC;'&gt;&lt;pre style='padding:0px;margin:0px;'&gt;&lt;br /&gt;&lt;BR&gt;package test;&lt;br /&gt;&lt;BR&gt;import com.esri.arcgis.webcontrols.faces.event.*;&lt;br /&gt;&lt;BR&gt;import com.esri.arcgis.webcontrols.data.*;&lt;br /&gt;&lt;BR&gt;import com.esri.arcgis.webcontrols.ags.data.*;&lt;br /&gt;&lt;BR&gt;import java.util.*;&lt;br /&gt;&lt;BR&gt;import javax.faces.component.UIData;&lt;br /&gt;&lt;BR&gt;import javax.faces.model.SelectItem;&lt;br /&gt;&lt;BR&gt;import java.util.logging.*;&lt;br /&gt;&lt;BR&gt;import com.esri.arcgis.geodatabase.*;&lt;br /&gt;&lt;BR&gt;import com.esri.arcgis.carto.ILayerDescriptions; &lt;br /&gt;&lt;BR&gt;&lt;br /&gt;&lt;BR&gt;public class AGSSelectionLayer implements &lt;br /&gt;&lt;BR&gt; WebContextInitialize, WebContextObserver{&lt;br /&gt;&lt;BR&gt;   private static Logger logger = &lt;br /&gt;&lt;BR&gt;  Logger.getLogger(AGSSelectionLayer.class.getName());&lt;br /&gt;&lt;BR&gt;   private AGSWebContext agsContext;&lt;br /&gt;&lt;BR&gt;   private String mapName;&lt;br /&gt;&lt;BR&gt;   private int layerId = 0;&lt;br /&gt;&lt;BR&gt;   public void init(WebContext agsContext) {&lt;br /&gt;&lt;BR&gt;       if(agsContext == null || &lt;br /&gt;              !(agsContext instanceof AGSWebContext)) &lt;br /&gt;&lt;BR&gt;            throw new IllegalArgumentException&lt;br /&gt;&lt;BR&gt;  (&amp;quot;WebContext null.&amp;quot;);&lt;br /&gt;&lt;BR&gt;       this.agsContext = (AGSWebContext)agsContext;&lt;br /&gt;&lt;BR&gt;       setLayerId(((Integer)((SelectItem)&lt;br /&gt;&lt;BR&gt;  ((AGSWebMap)agsContext.&lt;br /&gt;             getWebMap()).getFeatureLayers()&lt;br /&gt;          .get(0)).getValue()).intValue());&lt;br /&gt;&lt;BR&gt;   }&lt;br /&gt;&lt;BR&gt;&lt;br /&gt;&lt;BR&gt;   public void update(WebContext context, Object arg) {&lt;br /&gt;&lt;BR&gt;      if(arg == null || &lt;br /&gt;            arg != AGSRefreshId.DATA_FRAME_CHANGED)&lt;br /&gt;               return;&lt;br /&gt;&lt;BR&gt;      AGSWebMap agsMap = ((AGSWebMap)&lt;br /&gt;               agsContext.getWebMap());&lt;br /&gt;&lt;BR&gt;      this.mapName = agsMap.getFocusMapName();&lt;br /&gt;&lt;BR&gt;      setLayerId(((Integer)((SelectItem)&lt;br /&gt;&lt;BR&gt;  agsMap.getFeatureLayers()&lt;br /&gt;       .get(0)).getValue()).intValue());&lt;br /&gt;&lt;BR&gt;   }&lt;br /&gt;&lt;BR&gt; &lt;br /&gt;&lt;BR&gt;   public int getLayerId() {&lt;br /&gt;&lt;BR&gt;       return layerId; &lt;br /&gt;&lt;BR&gt;   }&lt;br /&gt;&lt;BR&gt;&lt;br /&gt;&lt;BR&gt;   public void setLayerId(int layerId) {&lt;br /&gt;&lt;BR&gt;       this.layerId = layerId; &lt;br /&gt;&lt;BR&gt;       AGSSelection selection = (AGSSelection)agsContext&lt;br /&gt;&lt;BR&gt;  .getAttribute(&lt;br /&gt;          AGSSelection.WEB_CONTEXT_ATTRIBUTE_NAME&lt;br /&gt;            );&lt;br /&gt;&lt;BR&gt;       selection.setSelectedLayerId(layerId);&lt;br /&gt;&lt;BR&gt;   }&lt;br /&gt;&lt;BR&gt; &lt;br /&gt;&lt;BR&gt;   public void clearResults() {&lt;br /&gt;&lt;BR&gt;      try { &lt;br /&gt;&lt;BR&gt;          ILayerDescriptions layerDescs = &lt;br /&gt;&lt;BR&gt;  ((AGSWebMap)agsContext.getWebMap()).&lt;br /&gt;&lt;BR&gt;   getFocusMapDescription().getLayerDescriptions();&lt;br /&gt;&lt;BR&gt;          for(int i = 0; i &amp;lt; layerDescs.getCount(); ++i) &lt;br /&gt;&lt;BR&gt;  layerDescs.getElement(i).setSelectionFeatures(null); &lt;br /&gt;&lt;BR&gt;      } catch(Exception _) { &lt;br /&gt;&lt;BR&gt;         logger.log(Level.WARNING,&lt;br /&gt;              &amp;quot;Unable to deselect features.&amp;quot;,&lt;br /&gt;                _); &lt;br /&gt;&lt;BR&gt;      } &lt;br /&gt;&lt;BR&gt;      agsContext.refresh(AGSRefreshId.MAP_OPERATION);&lt;br /&gt;&lt;BR&gt;   }&lt;br /&gt;&lt;BR&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Notice that on init method, we are calling setLayerId method and passing the first featurelayer from the collection in the wemap. setLayerId method sets the selection layer to the AGSSelection object. clearResults method clears out selection from all layers.&lt;br /&gt;&lt;br /&gt;5. Go to webapp_name/WEB-INF/classes folder and open managed_context_attributes.xml file in a text editor. Add a new managed-context-attribute as shown below:&lt;br /&gt;&lt;div style='background-color:whitesmoke;width:300px;font-family:courier;border:solid 2px #CCCCCC;'&gt;&lt;pre style='padding:0px;margin:0px;'&gt;&lt;br /&gt;&lt;BR&gt;&amp;lt;managed-context-attribute&amp;gt;&lt;br /&gt;&lt;BR&gt; &amp;lt;name&amp;gt;esriAGSSelectionLayer&amp;lt;/name&amp;gt;&lt;br /&gt;&lt;BR&gt; &amp;lt;attribute-class&amp;gt;test.AGSSelectionLayer&amp;lt;/attribute-class&amp;gt;&lt;br /&gt;&lt;BR&gt; &amp;lt;description&amp;gt;Selection Layer&amp;lt;/description&amp;gt;&lt;br /&gt;&lt;BR&gt;&amp;lt;/managed-context-attribute&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;6. Open mapviewer.jsp file from webapp folder and find the IMG tag for identify tool. Add the following code right after it to add a dropdown list of all FeatureLayers, a Selection tool and a button to clear selection.&lt;br /&gt;&lt;div style='background-color:whitesmoke;width:300px;font-family:courier;border:solid 2px #CCCCCC;'&gt;&lt;pre style='padding:0px;margin:0px;'&gt;&lt;br /&gt;&lt;BR&gt;&amp;lt;td&amp;gt;&lt;br /&gt;&lt;BR&gt;Select From:&lt;br /&gt;&lt;BR&gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;BR&gt;&amp;lt;td&amp;gt;&lt;br /&gt;&lt;BR&gt;lt;jsfh:selectOneMenu onchange=&amp;quot;this.form.submit();&amp;quot; &lt;br /&gt;&lt;BR&gt;value=&amp;quot;#{sessionScope['mapContext'].&lt;br /&gt;attributes['esriAGSSelectionLayer'].&lt;br /&gt;layerId}&amp;quot;&amp;gt;&lt;br /&gt;&lt;BR&gt;&amp;lt;jsfc:selectItems value=&amp;quot;#{sessionScope['mapContext'].&lt;br /&gt;webMap.featureLayers}&lt;br /&gt;&amp;quot;/&amp;gt;&lt;br /&gt;&lt;BR&gt;   &amp;lt;/jsfh:selectOneMenu&amp;gt; &lt;br /&gt;&lt;BR&gt; &amp;lt;/td&amp;gt;&lt;br /&gt;&lt;BR&gt; &amp;lt;td&amp;gt;              &lt;br /&gt;&lt;BR&gt; &amp;lt;IMG id=&amp;quot;imgSelection&amp;quot; &lt;br /&gt;      name=&amp;quot;imgSelection&amp;quot; &lt;br /&gt;      src=&amp;quot;images/polygon.gif&amp;quot; &lt;br /&gt;      alt=&amp;quot;select&amp;quot;&lt;br /&gt;      title=&amp;quot;Select&amp;quot;&lt;br /&gt;      onmouseover=&amp;quot;this.src='images/polygonU.gif'&amp;quot; &lt;br /&gt;      onmousedown=&amp;quot;this.src='images/polygonD.gif';&lt;br /&gt;                MapDragRectangle('Map0', 'Selection');&lt;br /&gt;         HighlightTool('Selection');&amp;quot;&lt;br /&gt;   onmouseout=&amp;quot;ButtonOut('imgSelection', 'Map0',&lt;br /&gt;     'Selection', 'images/polygon.gif',&lt;br /&gt;         'images/polygonD.gif')&amp;quot;&amp;gt;&lt;br /&gt;&lt;BR&gt;    &amp;lt;/td&amp;gt;&lt;br /&gt;&lt;BR&gt;    &amp;lt;td&amp;gt;&lt;br /&gt;&lt;BR&gt; &amp;lt;jsfh:commandButton id=&amp;quot;cmdClear&amp;quot;&lt;br /&gt;          image=&amp;quot;images/cancel.gif&amp;quot; &lt;br /&gt;          onmousedown=&amp;quot;this.src='images/cancelD.gif'&amp;quot; &lt;br /&gt;         onmouseover=&amp;quot;this.src='images/cancelU.gif'&amp;quot; &lt;br /&gt;        onmouseout=&amp;quot;this.src='images/cancel.gif'&amp;quot; &lt;br /&gt;      title=&amp;quot;Clear Selection&amp;quot; &lt;br /&gt;      alt=&amp;quot;Clear Selection&amp;quot; &lt;br /&gt;     action=&amp;quot;#{sessionScope['mapContext'].&lt;br /&gt;      attributes['esriAGSSelectionLayer'].clearResults}&amp;quot; /&amp;gt;&lt;br /&gt;&lt;BR&gt;    &amp;lt;/td&amp;gt;&lt;br /&gt;&lt;BR&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;7. Open templates.js file in a text editor from js folder and find HighlightTool function. Modify this function as shown below to include the Selection tool.&lt;br /&gt;&lt;BR&gt;&lt;BR&gt;&lt;br /&gt;&lt;div style='background-color:whitesmoke;width:300px;font-family:courier;border:solid 2px #CCCCCC;'&gt;&lt;pre style='padding:0px;margin:0px;'&gt;&lt;br /&gt;&lt;BR&gt;                   function HighlightTool(tool)&lt;br /&gt;&lt;BR&gt;   {&lt;br /&gt;&lt;BR&gt;    if ((tool!=null) &amp;&amp; (tool!=&amp;quot;&amp;quot;))&lt;br /&gt;&lt;BR&gt;    {&lt;br /&gt;&lt;BR&gt;     document.images[&amp;quot;imgZoomIn&amp;quot;].src = &amp;quot;images/zoomin.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;     document.images[&amp;quot;imgZoomOut&amp;quot;].src = &amp;quot;images/zoomout.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;     document.images[&amp;quot;imgPan&amp;quot;].src = &amp;quot;images/pan.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;     document.images[&amp;quot;imgIdentify&amp;quot;].src = &amp;quot;images/identify.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;     document.images[&amp;quot;imgSelection&amp;quot;].src = &amp;quot;images/polygon.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;     switch (tool)&lt;br /&gt;&lt;BR&gt;     {&lt;br /&gt;&lt;BR&gt;      case &amp;quot;ZoomIn&amp;quot;:&lt;br /&gt;&lt;BR&gt;       document.images[&amp;quot;imgZoomIn&amp;quot;].src = &amp;quot;images/zoominD.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;       break;&lt;br /&gt;&lt;BR&gt;      case &amp;quot;ZoomOut&amp;quot;:&lt;br /&gt;&lt;BR&gt;       document.images[&amp;quot;imgZoomOut&amp;quot;].src = &amp;quot;images/zoomoutD.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;       break;&lt;br /&gt;&lt;BR&gt;      case &amp;quot;Pan&amp;quot;:&lt;br /&gt;&lt;BR&gt;       document.images[&amp;quot;imgPan&amp;quot;].src = &amp;quot;images/panD.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;       break;&lt;br /&gt;&lt;BR&gt;      case &amp;quot;Identify&amp;quot;:&lt;br /&gt;&lt;BR&gt;       document.images[&amp;quot;imgIdentify&amp;quot;].src = &amp;quot;images/identifyD.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;       break;&lt;br /&gt;&lt;BR&gt;      case &amp;quot;Selection&amp;quot;:&lt;br /&gt;&lt;BR&gt;       document.images[&amp;quot;imgSelection&amp;quot;].src = &amp;quot;images/polygonD.gif&amp;quot;;&lt;br /&gt;&lt;BR&gt;       break;&lt;br /&gt;&lt;BR&gt;      default:&lt;br /&gt;&lt;BR&gt;     }&lt;br /&gt;&lt;BR&gt;    }&lt;br /&gt;&lt;BR&gt;  }&lt;br /&gt;&lt;BR&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;8. Open command prompt and CD to ant folder. Run this command: arcgisant build &lt;br /&gt;&lt;br /&gt;9. Verify that the SelectionTest.war file is created in build folder. Copy this file back to the ArcGIS Installation Directory\DeveloperKit\Templates\Java\build directory. &lt;br /&gt;&lt;br /&gt;10. Copy the webapp folder back to the ArcGIS Installation Directory\DeveloperKit\Templates\Java\build directory. &lt;br /&gt;&lt;br /&gt;11. Use arcgisant tool to deploy the web application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-113046134860946381?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/113046134860946381/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=113046134860946381' title='333 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/113046134860946381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/113046134860946381'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/10/adding-selection-tool-to-mapviewer.html' title='Adding Selection tool to MapViewer template'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>333</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112985990727958734</id><published>2005-10-20T18:57:00.000-07:00</published><updated>2005-10-21T16:17:51.900-07:00</updated><title type='text'>ANT tool for customizing ArcGIS Server application</title><content type='html'>IDE projects introduce unnecessary complication and overhead. So I typically limit the use of IDE for Java development to build classes. This way I can keep my project simple and easily managable. Ant tool can instead be used for project development and deployment. ArcGIS Server uses ant for configuration and deployment of template application. It can also be used for extending the template web applications. I use the following approach to customize the ArcGIS Server java template web applications:&lt;br /&gt;&lt;br /&gt;1. Create a workspace folder in a convenient place in your local directory. For example: C:/Temp/AGSProjects&lt;br /&gt;&lt;br /&gt;2. Inside the workspace folder, create the project folder. For example: C:/Temp/AGSProjects/MapProject1&lt;br /&gt;&lt;br /&gt;3. Inside the project folder, create this folder structure:&lt;br /&gt;   MapProject1&lt;br /&gt;&amp;nbsp;&amp;nbsp;  |-ant&lt;br /&gt;&amp;nbsp;&amp;nbsp;  |-build&lt;br /&gt;&amp;nbsp;&amp;nbsp;  |-src&lt;br /&gt;&lt;br /&gt;4. Use arcgisant tool to create an ArcGIS Server java template web application. Refer to ArcGIS Server Administration and Development Guide for more information.&lt;br /&gt; &lt;br /&gt;5. Copy the web application folder built in ArcGIS\DeveloperKit\Templates\Java\build folder to the projectfolder. (MapProject1 folder in the above example.)&lt;br /&gt;&lt;br /&gt;6. Create a file named build.xml with the following content:&lt;br /&gt;&lt;div style='background-color:whitesmoke;font-family:courier;border:solid 2px #CCCCCC;'&gt;&lt;br /&gt;&lt;pre style='padding:0px;margin:0px;'&gt;&lt;br /&gt;&amp;lt;project default="build" basedir="../" name="ags" &amp;gt; &lt;br /&gt;&amp;lt;!-- load environment variables --&amp;gt;&lt;br /&gt;&amp;lt;property environment="env"/&amp;gt; &lt;br /&gt;&amp;lt;property name="devkit.home" value="${env.AGSDEVKITHOME}" /&amp;gt; &lt;br /&gt;&amp;lt;property name="arcgisant.home" value="${devkit.home}/tools/ant"/&amp;gt; &lt;br /&gt;&amp;lt;!-- library dependency settings --&amp;gt;&lt;br /&gt;&amp;lt;property name="arcgis.dir" &lt;br /&gt;   location="${devkit.home}/Templates/Java/WEB-INF/lib"/&amp;gt;&lt;br /&gt;&amp;lt;!-- jar file mappings --&amp;gt;&lt;br /&gt;&amp;lt;property name="jintegra.jar" location="${arcgis.dir}/jintegra.jar"/&amp;gt;&lt;br /&gt;&amp;lt;property name="arcobjects.jar" &lt;br /&gt;   location="${arcgis.dir}/arcobjects.jar"/&amp;gt;&lt;br /&gt;&amp;lt;property name="arcgis_webcatalog.jar" &lt;br /&gt;   location="${arcgis.dir}/arcgis_webcatalog.jar"/&amp;gt;&lt;br /&gt;&amp;lt;!-- Project settings --&amp;gt;&lt;br /&gt;&amp;lt;property name="project.distname" value="MapViewer1"/&amp;gt;&lt;br /&gt;&amp;lt;!-- current project paths --&amp;gt;&lt;br /&gt;&amp;lt;property file="${basedir}/ant/build.properties"/&amp;gt;&lt;br /&gt;&amp;lt;property name="webroot.dir" value="${basedir}/${project.distname}"/&amp;gt;&lt;br /&gt;&amp;lt;property name="webinf.dir" value="${webroot.dir}/WEB-INF"/&amp;gt;&lt;br /&gt;&amp;lt;property name="src.dir" value="${basedir}/src"/&amp;gt;&lt;br /&gt;&amp;lt;property name="build.dir" value="build"/&amp;gt;&lt;br /&gt;&amp;lt;path id="arcgis.classpath"&amp;gt;&lt;br /&gt; &amp;lt;fileset dir="${arcgis.dir}"&amp;gt;&lt;br /&gt;  &amp;lt;include name="*.jar" /&amp;gt;&lt;br /&gt; &amp;lt;/fileset&amp;gt;&lt;br /&gt;&amp;lt;/path&amp;gt;&lt;br /&gt;&amp;lt;!-- Check timestamp on files --&amp;gt; &lt;br /&gt;&amp;lt;target name="prepare"&amp;gt;&lt;br /&gt; &amp;lt;tstamp/&amp;gt;&lt;br /&gt;&amp;lt;/target&amp;gt;&lt;br /&gt;&amp;lt;!-- Copy any resource or configuration files --&amp;gt;&lt;br /&gt;&amp;lt;target name="resources" &lt;br /&gt;    description="Copy any resource or configuration files"&amp;gt;&lt;br /&gt; &amp;lt;copy todir="${webinf.dir}/classes" includeEmptyDirs="no"&amp;gt;&lt;br /&gt;  &amp;lt;fileset dir="${src.dir}"&amp;gt;&lt;br /&gt;   &amp;lt;patternset&amp;gt;&lt;br /&gt;    &amp;lt;include name="**/*.conf"/&amp;gt;&lt;br /&gt;    &amp;lt;include name="**/*.properties"/&amp;gt;&lt;br /&gt;    &amp;lt;include name="**/*.xml"/&amp;gt;&lt;br /&gt;   &amp;lt;/patternset&amp;gt;&lt;br /&gt;  &amp;lt;/fileset&amp;gt;&lt;br /&gt; &amp;lt;/copy&amp;gt;&lt;br /&gt;&amp;lt;/target&amp;gt;&lt;br /&gt;&amp;lt;!-- compile--&amp;gt;&lt;br /&gt;&amp;lt;target name="compile" depends="prepare,resources" &lt;br /&gt;    description="Compile the project classes"&amp;gt;&lt;br /&gt; &amp;lt;javac srcdir="${src.dir}" destdir="${webinf.dir}/classes"&amp;gt;&lt;br /&gt;  &amp;lt;classpath refid="arcgis.classpath"/&amp;gt;&lt;br /&gt; &amp;lt;/javac&amp;gt;&lt;br /&gt;&amp;lt;/target&amp;gt;&lt;br /&gt;&amp;lt;!-- Remove existing compiled classes --&amp;gt;&lt;br /&gt;&amp;lt;target name="clean" &lt;br /&gt;    description="Remove classes directory for clean build"&amp;gt;&lt;br /&gt; &amp;lt;delete dir="${webinf.dir}/classes"/&amp;gt;&lt;br /&gt; &amp;lt;mkdir dir="${webinf.dir}/classes"/&amp;gt;&lt;br /&gt;&amp;lt;/target&amp;gt;&lt;br /&gt;&amp;lt;!-- Build the project --&amp;gt;&lt;br /&gt;&amp;lt;target name="build1" description="Build the project" &lt;br /&gt;   depends="prepare,compile"/&amp;gt;&lt;br /&gt;&amp;lt;target name="rebuild" description="Rebuild the project"&lt;br /&gt;    depends="clean,prepare,compile"/&amp;gt;&lt;br /&gt;&amp;lt;!-- Create war file --&amp;gt;&lt;br /&gt;&amp;lt;target name="build" depends="build1" &lt;br /&gt;    description="Create the war file for deployment"&amp;gt;&lt;br /&gt;  &amp;lt;mkdir dir="${build.dir}"/&amp;gt;&lt;br /&gt;  &amp;lt;war basedir="${webroot.dir}" &lt;br /&gt;     warfile="${build.dir}/${project.distname}.war" &lt;br /&gt;       webxml="${webinf.dir}/web.xml"&amp;gt;&lt;br /&gt;   &amp;lt;exclude name="WEB-INF/${build.dir}/**"/&amp;gt;&lt;br /&gt;   &amp;lt;exclude name="WEB-INF/src/**"/&amp;gt;&lt;br /&gt;   &amp;lt;exclude name="WEB-INF/web.xml"/&amp;gt;&lt;br /&gt;  &amp;lt;/war&amp;gt;&lt;br /&gt; &amp;lt;/target&amp;gt;&lt;br /&gt;&amp;lt;/project&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;7. Change the value in this line in the build.xml file to the name of the web application you create above. &lt;br /&gt;&lt;br /&gt;&amp;lt;property name="project.distname" value="MapViewer1"/&amp;gt;&lt;br /&gt;&lt;br /&gt;8. Customize the web application as necessary.&lt;br /&gt;&lt;br /&gt;9. Add any java source code to src folder.&lt;br /&gt;&lt;br /&gt;10. Open command prompt and CD to ant directory in your project. Type this command to build the project:&lt;br /&gt; arcgisant build&lt;br /&gt;&lt;br /&gt;11. Verify that a war file is built in the build folder. Deploy this war file directly or copy the web application folder and the war file back to ArcGIS\DeveloperKit\Templates\Java\build folder and use arcgisant to deploy it.&lt;br /&gt;&lt;br /&gt;You can repeat the same steps to build any other web applications. You can use the same build file but make sure to update it with the new project name as mentioned above in step 7.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112985990727958734?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112985990727958734/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112985990727958734' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112985990727958734'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112985990727958734'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/10/ant-tool-for-customizing-arcgis-server.html' title='ANT tool for customizing ArcGIS Server application'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112787156281253176</id><published>2005-09-27T18:34:00.000-07:00</published><updated>2005-10-20T19:21:04.210-07:00</updated><title type='text'>Tutorial: Using Ajax in a JSF application - II</title><content type='html'>In part I, we have created a simple JSF application. Next we will implement Ajax into this application. This will require us to create i) a server side application to dynamically provide the data to the client and ii) client side javascript functions to request data and process the response.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1:  Create the servlet as a server side application. &lt;/strong&gt;&lt;br /&gt;Copy the following code and save it as AjaxServlet.java in ajax/Web-Inf/classes/demo folder: &lt;br /&gt;&lt;pre style='padding:0px;margin:0px;'&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package demo;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;import javax.servlet.ServletConfig;&lt;br /&gt;&lt;br&gt;import javax.servlet.ServletException;&lt;br /&gt;&lt;br&gt;import javax.servlet.http.HttpServlet;&lt;br /&gt;&lt;br&gt;import javax.servlet.http.HttpServletRequest;&lt;br /&gt;&lt;br&gt;import javax.servlet.http.HttpServletResponse;&lt;br /&gt;&lt;br&gt;import javax.servlet.http.HttpSession;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;public class AjaxServlet extends HttpServlet {&lt;br /&gt;&lt;br&gt; private ServletConfig servletConfig = null;&lt;br /&gt;&lt;br&gt; public void destroy() {&lt;br /&gt;&lt;br&gt;  servletConfig = null;&lt;br /&gt;&lt;br&gt; }&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt; public ServletConfig getServletConfig() {&lt;br /&gt;&lt;br&gt;   return (this.servletConfig);&lt;br /&gt;&lt;br&gt; }&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt; public String getServletInfo() {&lt;br /&gt;&lt;br&gt;  return (this.getClass().getName());&lt;br /&gt;&lt;br&gt; }&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt; public void init(ServletConfig servletConfig) &lt;br /&gt;&lt;br&gt;   throws ServletException {&lt;br /&gt;&lt;br&gt;  this.servletConfig = servletConfig;&lt;br /&gt;&lt;br&gt; }&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt; public void doGet(HttpServletRequest request,&lt;br /&gt;&lt;br&gt;          HttpServletResponse response)&lt;br /&gt;&lt;br&gt;    throws java.io.IOException,&lt;br /&gt;&lt;br&gt;           ServletException {&lt;br /&gt;&lt;br&gt; String key = (String)request.getParameter("key");&lt;br /&gt;&lt;br&gt; //get CountryBean object from ServletContext&lt;br /&gt;&lt;br&gt; CountryBean countryBean = (CountryBean) &lt;br /&gt;&lt;br&gt;  getServletContext().getAttribute("CountryBean");&lt;br /&gt;&lt;br&gt; //get list of countries&lt;br /&gt;&lt;br&gt; String[] countries = countryBean.getCountries();&lt;br /&gt;&lt;br&gt; //find matches&lt;br /&gt;&lt;br&gt; String matches = getMatches(countries, key);&lt;br /&gt;&lt;br&gt; //print it out to the client&lt;br /&gt;&lt;br&gt; response.setContentType("text/xml");&lt;br /&gt;&lt;br&gt; java.io.PrintWriter out=response.getWriter();&lt;br /&gt;&lt;br&gt; out.print(matches);&lt;br /&gt;&lt;br&gt; out.flush();&lt;br /&gt;&lt;br&gt;}&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt; public void doPost(HttpServletRequest request,&lt;br /&gt;&lt;br&gt;              HttpServletResponse response)&lt;br /&gt;&lt;br&gt;   throws java.io.IOException,&lt;br /&gt;&lt;br&gt;            ServletException {&lt;br /&gt;&lt;br&gt;  doGet(request, response);&lt;br /&gt;&lt;br&gt; }&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt; private String getMatches(&lt;br /&gt;&lt;br&gt;      String[] countries, String key){&lt;br /&gt;&lt;br&gt;  //generate xml response&lt;br /&gt;&lt;br&gt;  String cList = "&amp;lt;?xml version=\"1.0\" ";&lt;br /&gt;&lt;br&gt;  cList += "encoding=\"UTF-8\" ?&amp;gt;";&lt;br /&gt;&lt;br&gt;  cList +="&amp;lt;COUNTRIES&amp;gt;";&lt;br /&gt;&lt;br&gt;  int count = 0;&lt;br /&gt;&lt;br&gt;  //from countries list find first 5 matches&lt;br /&gt;&lt;br&gt;  for(int i=0;i&amp;lt;countries.length;i++){&lt;br /&gt;&lt;br&gt;   if(countries[i].toUpperCase().&lt;br /&gt;&lt;br&gt;        startsWith(key.toUpperCase())){&lt;br /&gt;&lt;br&gt;    cList += "&amp;lt;COUNTRY name=\"" + countries[i] + "\" /&amp;gt;";&lt;br /&gt;&lt;br&gt;    count++;&lt;br /&gt;&lt;br&gt;    if(count == 5) break;&lt;br /&gt;&lt;br&gt;   }&lt;br /&gt;&lt;br&gt;  }&lt;br /&gt;&lt;br&gt;  cList += "&amp;lt;TOTALCOUNT count=\"" + count + "\" /&amp;gt;";&lt;br /&gt;&lt;br&gt;  cList += "&amp;lt;/COUNTRIES&amp;gt;";&lt;br /&gt;&lt;br&gt;  return cList;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt; }&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In doGet method of the above code, we first get the value of "key" &lt;br /&gt;parameter submitted from the client. Next, we get the JSF managed &lt;br /&gt;CountryBean from which we obtain a list of countries and store &lt;br /&gt;it in a String array:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;CountryBean countryBean = (CountryBean) &lt;br /&gt; getServletContext().getAttribute("CountryBean");&lt;br /&gt;//get list of countries&lt;br /&gt;String[] countries = countryBean.getCountries();&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;We then call getMatches method to check for country names that start with the key string sent by the user. This is, of course, a very simple method but you can substitute it with your own advanced code. &lt;br /&gt;&lt;br /&gt;Notice also that this method generates an XML document with a list of matching country names. Finally the XML document is sent to the client.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2: Configure the Servlet&lt;/strong&gt;&lt;br /&gt;Open web.xml file from ajax/WEB-INF folder and add the custom servlet right after Faces Servlet:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&amp;lt;servlet&amp;gt;&lt;br /&gt;&lt;br&gt; &amp;lt;servlet-name&amp;gt;AjaxServlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;&lt;br&gt; &amp;lt;servlet-class&amp;gt;demo.AjaxServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;&lt;br&gt;&amp;lt;/servlet&amp;gt; &lt;br /&gt;&lt;br&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;    &lt;br /&gt;Add this servlet mapping after Faces Servlet mapping:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br&gt;&amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;&lt;br&gt;  &amp;lt;servlet-name&amp;gt;AjaxServlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;&lt;br&gt;  &amp;lt;url-pattern&amp;gt;/AjaxServlet&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;&lt;br&gt;&amp;lt;/servlet-mapping&amp;gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 3: Add javascript code to the application&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Download the script.js file from &lt;a href="http://www.geocities.com/sekharkafle/ajax_script.zip"&gt;here&lt;/a&gt; and copy it to ajax/js folder. &lt;br /&gt;&lt;br /&gt;Notice in the js file that the following code creates the XMLHTTPRequest object.&lt;br /&gt;(Also notice the difference in the code for creating this object in IE vs Mozilla.)&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var req;&lt;br /&gt;&lt;br /&gt;//initialize the XMLHttpRequest object&lt;br /&gt;if (window.XMLHttpRequest) {&lt;br /&gt; req = new XMLHttpRequest();&lt;br /&gt;} else if (window.ActiveXObject) {&lt;br /&gt; req = new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The function initPopup is responsible for turning off the autocomplete&lt;br /&gt; feature of the browser. It also gets the location of the autocomplete &lt;br /&gt;text-box and positions the popup element right below it. We will call &lt;br /&gt;this function after the page is loaded.&lt;br /&gt;&lt;br /&gt;The function doMouseClick is called when an item is selected in &lt;br /&gt;popup list. This function sets the item value to the text box.&lt;br /&gt;&lt;br /&gt;The functions hidePopup and showPopup simply hide and show the &lt;br /&gt;popup element.&lt;br /&gt;&lt;br /&gt;The function getQuery uses the XMLHttpRequest object and submits&lt;br /&gt; the current text-box value to the AjaxServlet. Notice the path to our custom AjaxServlet configured above and how the key value is appended to the URL:&lt;br /&gt;var url = "/ajax/AjaxServlet?key=" + key;  &lt;br /&gt;&lt;br /&gt;Also, notice the following line in this function:&lt;br /&gt;req.onreadystatechange = processResponse;&lt;br /&gt;&lt;br /&gt;The above line indicates that the processResponse function is called &lt;br /&gt;when the response is received by the client. The processResponse &lt;br /&gt;function forwards the response to parseResponse function.&lt;br /&gt;&lt;br /&gt;The parseResponse function processes the response from the server.&lt;br /&gt;Remember that the response is an XML document. So this function parses the XML document using dom parser and extracts the country names. &lt;br /&gt;The country names will then be added to the popup CSS element which will then be displayed by setting its visibility to true.&lt;br /&gt;&lt;br /&gt;The following code is required for Mozilla since it does not implement loadXML method by default. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//check if it is IE&lt;br /&gt;var isIE = (window.navigator.appName.toLowerCase().indexOf("microsoft")&gt;=0);&lt;br /&gt;&lt;br /&gt;//implement loadXML method for Mozilla since it is not supported&lt;br /&gt; if(!isIE){&lt;br /&gt; Document.prototype.loadXML = function (s) {&lt;br /&gt;&lt;br /&gt;     // parse the string to a new doc&lt;br /&gt;     var doc2 = (new DOMParser()).parseFromString(s, "text/xml");&lt;br /&gt;&lt;br /&gt;     // remove all initial children&lt;br /&gt;     while (this.hasChildNodes())&lt;br /&gt;        this.removeChild(this.lastChild);&lt;br /&gt;&lt;br /&gt;     // insert and import nodes&lt;br /&gt;     for (var i = 0; i &amp;lt; doc2.childNodes.length; i++) {&lt;br /&gt;        this.appendChild(this.importNode(doc2.childNodes[i], true));&lt;br /&gt;     }&lt;br /&gt;       };&lt;br /&gt;}  &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;Step 4: Reference the javascript code in JSP page&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Add this line within the HEAD of jsp code:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="js/script.js"&amp;gt;&amp;lt;/SCRIPT&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;strong&gt;Step 5: Enable ajax for input text&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Modify the inputText component as follows: &lt;br /&gt;&lt;code&gt;&lt;br /&gt; &amp;lt;h:inputText id="autoText" onblur="hidePopup()" onfocus="getQuery(this.value)" onkeyup="getQuery(this.value)" value="#SelectedCountryRecord.selectedCountry}" /&amp;gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Notice that on-focus and on-key-up (i.e. whenever a key is pressed &lt;br /&gt;and released), we call getQuery function to submit a new request &lt;br /&gt;to the server to get updated list. On-blur, we hide the popup list.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 6: Create popup div element&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Add this code right before the end tag for body:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;div align="left" class="box" id="autocomplete" &lt;br /&gt;style="WIDTH:170px;visibility:hidden;&lt;br /&gt;       BACKGROUND-COLOR:#ccccff"&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"&amp;gt;&lt;br /&gt;  initPopup('_id0:autoText','autocomplete');&lt;br /&gt;&amp;lt;/SCRIPT&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;First we define the div element for popup. We then call initPopup javascript&lt;br /&gt;function to size and position the popup element.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112787156281253176?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112787156281253176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112787156281253176' title='56 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112787156281253176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112787156281253176'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/09/tutorial-using-ajax-in-jsf-application_27.html' title='Tutorial: Using Ajax in a JSF application - II'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>56</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112605310636955264</id><published>2005-09-06T20:12:00.000-07:00</published><updated>2005-09-06T18:10:26.630-07:00</updated><title type='text'>Tutorial: Using Ajax in a JSF application - I</title><content type='html'>This tutorial is intended to provide a hands-on experience on implementing an auto-complete &lt;a href="http://www.google.com/webhp?complete=1&amp;hl=en"&gt;Google suggest &lt;/a&gt;like TextBox in a JSF application. As mentioned &lt;a href="http://kafle.blogspot.com/2005/08/using-ajax-in-simple-jsf-application.html"&gt;before&lt;/a&gt;, we will not create a reusable custom textbox component but rather take a simple approach of using the standard JSF HTML Textbox. This means we will manage the necessary Javascript code in the web application on our own. The application being discussed here would be more useful for a web developer rather than a component developer.&lt;br /&gt;&lt;br /&gt;As mentioned &lt;a href="http://kafle.blogspot.com/2005/08/using-ajax-in-simple-jsf-application.html"&gt;earlier&lt;/a&gt;, the application will contain a text box to enter a country name. As you type a new character in the text box, it will dynamically get upto 5 matching country names from the servlet and list those names for you to choose from. Once you select a country in the text box and submit the form, it will display a brief description of the selected country. The application itself is pretty simple but it intends to provide the following 2 key concepts:&lt;br /&gt;1. How can we implement a Servlet in a JSF web application to interact with the browser in the client side as well as to interact with the JSF components in the server side to possibly update the server state?&lt;br /&gt;2. How can we implement the Javascript code in the application for Ajax implementation in the client side?&lt;br /&gt;&lt;br /&gt;In this part, we will create a simple JSF application without AJAX. In part II, we will extend the same application to implement AJAX.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1: Set up the JSF application framework.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This tutorial is not an introduction to JSF. It is assumed that you already know how to create a JSF application. So the basic framework for this application is already provided. Download it from &lt;a href="http://www.geocities.com/sekharkafle/ajaxempty.zip"&gt;here&lt;/a&gt; and extract it to a folder in your computer. Notice the structure of the extracted files:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;ajax&lt;br /&gt; |-country.jsp&lt;br /&gt; |-index.jsp&lt;br /&gt; |-WEB-INF&lt;br /&gt;       |-faces-config.xml&lt;br /&gt;       |-web.xml&lt;br /&gt;       |-lib&lt;br /&gt;       |-classes&lt;br /&gt;             |-demo&lt;br /&gt;                |-country.data&lt;br /&gt;       &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2. Add JSF libraries&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Add the JSF jar files to ajax/Web-Inf/lib folder.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Step 3: Store the data. &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;To keep things simple, we will store the country data in a simple txt file separated by tab. In a real world application though, the data would be queried dynamically from the database, web services or some other sources. &lt;br /&gt;As shown above, the data is already provided in ajax/web-inf/classes/demo/country.data file and is stored in this format:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Luxembourg Western Europe Europe Luxembourg LU&lt;br /&gt;Switzerland Western Europe Europe Bern SZ&lt;br /&gt;France Western Europe Europe Paris FR&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 4: Read data.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;We will read the data from the txt file when the application is initially started and keep it in the memory. We could have read the datasource dynamically for each client request. However, in this simple case, it makes more sense to load the data once at the startup.&lt;br /&gt;&lt;br /&gt;Create the CountryBean.java file with the following content in ajax/Web-Inf/classes/demo folder: &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package demo;&lt;br /&gt;&lt;br /&gt;public class CountryBean{&lt;br /&gt; String[] countries;&lt;br /&gt; java.util.HashMap countryDetails = new java.util.HashMap();&lt;br /&gt; public CountryBean(){&lt;br /&gt;  try{&lt;br /&gt;   //read country data from the text file&lt;br /&gt;   java.io.BufferedReader in=&lt;br /&gt;      new java.io.BufferedReader(&lt;br /&gt;        new java.io.InputStreamReader(&lt;br /&gt;          CountryBean.this.getClass().&lt;br /&gt;           getResourceAsStream("country.data"&lt;br /&gt;       )));&lt;br /&gt;   readData(in);&lt;br /&gt;   in.close();&lt;br /&gt;   } catch (java.io.IOException IOex) {&lt;br /&gt;     System.out.println("IO Error :" +IOex);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;   //returns country data&lt;br /&gt;   public java.util.HashMap getCountryDetails(){&lt;br /&gt;      return countryDetails;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   //returns country list&lt;br /&gt;   public String[] getCountries(){&lt;br /&gt;      return countries;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   //read data from the text file &lt;br /&gt;   //and store it in countryDetails&lt;br /&gt;   private void readData(java.io.BufferedReader br)&lt;br /&gt;        throws java.io.IOException  {&lt;br /&gt;     int recordNum= Integer.parseInt(br.readLine());&lt;br /&gt;     countries = new String[recordNum];&lt;br /&gt;     for(int i=0; i&amp;lt;recordNum; i++){&lt;br /&gt;    String line=br.readLine();&lt;br /&gt;    java.util.StringTokenizer st = &lt;br /&gt;          new java.util.StringTokenizer(line, "\t\r");&lt;br /&gt;    String name= st.nextToken();&lt;br /&gt;    String region= st.nextToken();&lt;br /&gt;    String cont = st.nextToken();&lt;br /&gt;    String capital = st.nextToken();&lt;br /&gt;    String id = st.nextToken();&lt;br /&gt;    CountryRecord cr= new CountryRecord(name, region, cont, capital, id);&lt;br /&gt;    countryDetails.put(name, cr);&lt;br /&gt;    countries[i] = name;&lt;br /&gt;     }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The above class reads the data from the txt file. Notice that in the constructor, &lt;br /&gt;we are calling readData method. In the readData method, we are reading each line from the text file and using the data to create a CountryRecord object to represent each country. The CountryRecord objects are then stored in a HashMap variable named countryDetails. We have also created another String array variable named countries and stored the country names in it.&lt;br /&gt;The two methods getCountryDetails and getCountries simply return countryDetails and countries variables respectively so that they can be accessed from other places in the application.&lt;br /&gt;   &lt;br /&gt;&lt;strong&gt;Step 5: Add the class as a JSF managed bean&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Open faces-config.xml from ajax/web-inf folder and add the above class as a managed bean as shown below:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;managed-bean&amp;gt;&lt;br /&gt; &amp;lt;managed-bean-name&amp;gt;CountryBean&amp;lt;/managed-bean-name&amp;gt;&lt;br /&gt; &amp;lt;managed-bean-class&amp;gt;demo.CountryBean&amp;lt;/managed-bean-class&amp;gt;&lt;br /&gt; &amp;lt;managed-bean-scope&amp;gt;application&amp;lt;/managed-bean-scope&amp;gt;&lt;br /&gt;&amp;lt;/managed-bean&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Notice that we have added the bean with application scope because we want to &lt;br /&gt;create a single instance of CountryBean throught the lifecycle of the application so that the database is read just once when the application starts.      &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 6: Create CountryRecord class&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The CountryRecord class we used above is a simple class to store each of the country record. Create the CountryRecord.java file with the following content in ajax/Web-Inf/classes/demo folder:   &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package demo;&lt;br /&gt;public class CountryRecord {&lt;br /&gt; String name;&lt;br /&gt; String region;&lt;br /&gt; String continent;&lt;br /&gt; String capital;&lt;br /&gt; String id;&lt;br /&gt;&lt;br /&gt; public CountryRecord(String name,&lt;br /&gt;                      String region,&lt;br /&gt;                      String continent,&lt;br /&gt;                      String capital,&lt;br /&gt;                      String id){&lt;br /&gt;  this.name=name;&lt;br /&gt;  this.region=region;&lt;br /&gt;  this.continent=continent;&lt;br /&gt;  this.capital = capital;&lt;br /&gt;  this.id=id;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getName(){&lt;br /&gt;  return name;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getRegion(){&lt;br /&gt;  return region;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getContinent(){&lt;br /&gt;  return continent;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getCapital(){&lt;br /&gt;  return capital;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getId(){&lt;br /&gt;  return id;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 7: Create a class to store the selected country information&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Next we will create a class to store the state of the user selection. In this case, it is the Selected Country Record. Create the SelectedCountryRecord.java file with the following content in ajax/Web-Inf/classes/demo folder:  &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package demo;&lt;br /&gt;public class SelectedCountryRecord{&lt;br /&gt; String selectedCountry;&lt;br /&gt; CountryRecord selectedCountryRecord;&lt;br /&gt; java.util.HashMap countryDetails;&lt;br /&gt;&lt;br /&gt; public SelectedCountryRecord(){&lt;br /&gt;  setCountryDetails();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getSelectedCountry(){&lt;br /&gt;  return selectedCountry;&lt;br /&gt; }&lt;br /&gt; public void setSelectedCountry(String selectedCountry){&lt;br /&gt;  this.selectedCountry = selectedCountry;&lt;br /&gt;  setSelectedCountryRecord();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getName(){&lt;br /&gt;  if(selectedCountryRecord != null)&lt;br /&gt;     return selectedCountryRecord.getName();&lt;br /&gt;  else return null;&lt;br /&gt; }&lt;br /&gt; public String getRegion(){&lt;br /&gt;  if(selectedCountryRecord != null)&lt;br /&gt;      return selectedCountryRecord.getRegion();&lt;br /&gt;  else return null;&lt;br /&gt; }&lt;br /&gt; public String getContinent(){&lt;br /&gt;  if(selectedCountryRecord != null)&lt;br /&gt;     return selectedCountryRecord.getContinent();&lt;br /&gt;  else return null;&lt;br /&gt; }&lt;br /&gt; public String getCapital(){&lt;br /&gt;  if(selectedCountryRecord != null)&lt;br /&gt;     return selectedCountryRecord.getCapital();&lt;br /&gt;  else return null;&lt;br /&gt; }&lt;br /&gt; public String getId(){&lt;br /&gt;  if(selectedCountryRecord != null) {&lt;br /&gt;   if (selectedCountryRecord.getId() != "") {&lt;br /&gt;     String id = "http://www.cia.gov/cia/publications/factbook/geos/"&lt;br /&gt;        + selectedCountryRecord.getId().toLowerCase() + ".html";&lt;br /&gt;     return id;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  return null;&lt;br /&gt; }&lt;br /&gt; public boolean isSelected(){&lt;br /&gt;  if(selectedCountryRecord != null) return true;&lt;br /&gt;  else return false;&lt;br /&gt; }&lt;br /&gt; public void setSelectedCountryRecord(){&lt;br /&gt;   if(selectedCountry != null) {&lt;br /&gt;    Object obj = countryDetails.get(selectedCountry);&lt;br /&gt;    if((obj != null) &amp;&amp; &lt;br /&gt;        (obj instanceof CountryRecord)) {&lt;br /&gt; selectedCountryRecord = (CountryRecord) obj;&lt;br /&gt;     } &lt;br /&gt;    else selectedCountryRecord=null;&lt;br /&gt;   } else selectedCountryRecord = null;&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  public void setCountryDetails(){&lt;br /&gt;    javax.faces.context.FacesContext context = &lt;br /&gt;      javax.faces.context.FacesContext.getCurrentInstance();&lt;br /&gt;    javax.faces.application.Application app = &lt;br /&gt;        context.getApplication();&lt;br /&gt;    CountryBean cBean = (CountryBean) &lt;br /&gt;         app.createValueBinding("#{CountryBean}").getValue(context);&lt;br /&gt;    countryDetails = cBean.getCountryDetails();&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The constructor of this class calls setCountryDetails() method:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public SelectedCountryRecord(){&lt;br /&gt;  setCountryDetails();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In the setCountryDetails method, we first get the Application object from FacesContext. &lt;br /&gt;Next, we will get the JSF managed CountryBean that we added above using JSF value binding expression. From the CountryBean, we will get the CountryDetails variable. Remember that this is a hashmap variable which stores the detail information of all countries. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public void setCountryDetails(){&lt;br /&gt;  javax.faces.context.FacesContext context = &lt;br /&gt;    javax.faces.context.FacesContext.getCurrentInstance();&lt;br /&gt;  javax.faces.application.Application app = &lt;br /&gt;      context.getApplication();&lt;br /&gt;   CountryBean cBean = (CountryBean) &lt;br /&gt;      app.createValueBinding("#{CountryBean}").getValue(context);&lt;br /&gt;   countryDetails = cBean.getCountryDetails();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The class level variables selectedCountry and selectedCountryRecord store the&lt;br /&gt;user selected country's name and CountryRecord object respectively. Here are the get and set methods for selectedCountry variable:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public String getSelectedCountry(){&lt;br /&gt; return selectedCountry;&lt;br /&gt;}&lt;br /&gt;public void setSelectedCountry(String selectedCountry){&lt;br /&gt; this.selectedCountry = selectedCountry;&lt;br /&gt; setSelectedCountryRecord();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;Notice that the set method calls setSelectedCountryRecord() method in addition&lt;br /&gt;to setting the new value. We are calling setSelectedCountryRecord method here because as the user enters a new value for country, we will update the value of selectedCountryRecord too for the new country. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public void setSelectedCountryRecord(){&lt;br /&gt; if(selectedCountry != null) {&lt;br /&gt;   Object obj = countryDetails.get(selectedCountry);&lt;br /&gt;    if((obj != null) &amp;&amp; (obj instanceof CountryRecord)){&lt;br /&gt;     selectedCountryRecord = (CountryRecord) obj;&lt;br /&gt;    } else selectedCountryRecord=null;&lt;br /&gt;  } else selectedCountryRecord = null;&lt;br /&gt;}   &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the above method, we are first getting the new CountryRecord object from &lt;br /&gt;the hashMap by passing the new selectCountry value :&lt;br /&gt;&lt;br /&gt;Object obj = countryDetails.get(selectedCountry);&lt;br /&gt;&lt;br /&gt;and then we are updating the selectedCountryRecord variable:&lt;br /&gt;  &lt;br /&gt;selectedCountryRecord = (CountryRecord) obj;&lt;br /&gt;&lt;br /&gt;The other methods getName(), getCapital(), getRegion(), getContinent(), getId()simply return the name, capital, region, continent and id respectively from the selectedCountryRecord variable. We will bind these methods with the JSP outputText components to display those values.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 8: Add SelectedCountryRecord as a managed bean&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Open faces-config.xml from ajax/web-inf folder and add the above class as a &lt;br /&gt;managed bean as shown below:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;managed-bean&amp;gt;&lt;br /&gt; &amp;lt;managed-bean-name&amp;gt;SelectedCountryRecord&amp;lt;/managed-bean-name&amp;gt;&lt;br /&gt; &amp;lt;managed-bean-class&amp;gt;demo.SelectedCountryRecord&amp;lt;/managed-bean-class&amp;gt;&lt;br /&gt; &amp;lt;managed-bean-scope&amp;gt;session&amp;lt;/managed-bean-scope&amp;gt;&lt;br /&gt;&amp;lt;/managed-bean&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Notice that this time we have added the bean with the session scope unlike &lt;br /&gt;the previous one. This is because this class contains the data of the selected country for a particular user session. Hence, we need to add it with session scope to create a separate instance to store the individual state of each user session.    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 9: Compile the above 3 classes&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Put the JSF and Servlet libraries in class path and compile the above classes. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 10: Create the JSP page&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Add this content to ajax/country.jsp file:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %&amp;gt;&lt;br /&gt;&amp;lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt; &amp;lt;head&amp;gt;&lt;br /&gt;    &amp;lt;title&amp;gt;Country Details&amp;lt;/title&amp;gt;&lt;br /&gt; &amp;lt;/head&amp;gt;&lt;br /&gt;  &amp;lt;body&amp;gt;&lt;br /&gt;   &amp;lt;f:view&amp;gt;&lt;br /&gt;     &amp;lt;h:form&amp;gt;&lt;br /&gt; &amp;lt;h:outputText &lt;br /&gt;           value="Integrating AJAX in a simple JSF Application" &lt;br /&gt;           styleClass="title"/&amp;gt;&lt;br /&gt; &amp;lt;br&amp;gt;&lt;br /&gt; &amp;lt;br&amp;gt;&lt;br /&gt; &amp;lt;h:outputText value="Enter Country : " /&amp;gt;&lt;br /&gt; &amp;lt;h:inputText id="autoText" &lt;br /&gt;                     value="#{SelectedCountryRecord.selectedCountry}" /&amp;gt; &lt;br /&gt; &amp;lt;h:commandButton value="OK" action="success"/&amp;gt;&lt;br /&gt; &amp;lt;hr&amp;gt;&lt;br /&gt; &lt;br /&gt;        &amp;lt;table&amp;gt;&lt;br /&gt;  &amp;lt;tr&amp;gt;&lt;br /&gt;   &amp;lt;td&amp;gt;&lt;br /&gt;     &amp;lt;h:outputText value="Country Details" &lt;br /&gt;                          rendered="#{SelectedCountryRecord.selected}"/&amp;gt;&lt;br /&gt;   &amp;lt;/td&amp;gt;&lt;br /&gt;  &amp;lt;/tr&amp;gt;&lt;br /&gt;  &amp;lt;tr&amp;gt;&lt;br /&gt;   &amp;lt;td&amp;gt;&lt;br /&gt;     &amp;lt;h:outputText value="Name : " &lt;br /&gt;                          rendered="#{SelectedCountryRecord.selected}"/&amp;gt;&lt;br /&gt;     &amp;lt;h:outputText value="#{SelectedCountryRecord.name}" /&amp;gt;&lt;br /&gt;   &amp;lt;/td&amp;gt;&lt;br /&gt;  &amp;lt;/tr&amp;gt;&lt;br /&gt;  &amp;lt;tr&amp;gt;&lt;br /&gt;   &amp;lt;td&amp;gt;&lt;br /&gt;    &amp;lt;h:outputText value="Region : " &lt;br /&gt;                         rendered="#{SelectedCountryRecord.selected}"/&amp;gt;&lt;br /&gt;    &amp;lt;h:outputText value="#{SelectedCountryRecord.region}" /&amp;gt;&lt;br /&gt;   &amp;lt;/td&amp;gt;&lt;br /&gt;  &amp;lt;/tr&amp;gt;&lt;br /&gt;  &amp;lt;tr&amp;gt;&lt;br /&gt;   &amp;lt;td&amp;gt;&lt;br /&gt;    &amp;lt;h:outputText value="Continent : " &lt;br /&gt;                         rendered="#{SelectedCountryRecord.selected}"/&amp;gt;&lt;br /&gt;    &amp;lt;h:outputText value="#{SelectedCountryRecord.continent}" /&amp;gt;&lt;br /&gt;   &amp;lt;/td&amp;gt;&lt;br /&gt;  &amp;lt;/tr&amp;gt;&lt;br /&gt;  &amp;lt;tr&amp;gt;&lt;br /&gt;   &amp;lt;td&amp;gt;&lt;br /&gt;    &amp;lt;h:outputText value="Capital : " &lt;br /&gt;                         rendered="#{SelectedCountryRecord.selected}"/&amp;gt;&lt;br /&gt;    &amp;lt;h:outputText value="#{SelectedCountryRecord.capital}" /&amp;gt;&lt;br /&gt;   &amp;lt;/td&amp;gt;&lt;br /&gt;  &amp;lt;/tr&amp;gt;&lt;br /&gt;  &amp;lt;tr&amp;gt;&lt;br /&gt;   &amp;lt;td&amp;gt;&lt;br /&gt;    &amp;lt;h:outputText value="More Descriptions : " &lt;br /&gt;                         rendered="#{SelectedCountryRecord.selected}"/&amp;gt;&lt;br /&gt;    &amp;lt;h:outputLink value="#{SelectedCountryRecord.id}"&amp;gt;&lt;br /&gt;      &amp;lt;h:outputText value="#{SelectedCountryRecord.id}" /&amp;gt;&lt;br /&gt;     &amp;lt;/h:outputLink&amp;gt;&lt;br /&gt;   &amp;lt;/td&amp;gt;&lt;br /&gt;  &amp;lt;/tr&amp;gt;&lt;br /&gt; &amp;lt;/table&amp;gt;&lt;br /&gt;    &amp;lt;/h:form&amp;gt;&lt;br /&gt;  &amp;lt;/f:view&amp;gt;&lt;br /&gt;   &lt;br /&gt; &amp;lt;/body&amp;gt; &lt;br /&gt;&amp;lt;/html&amp;gt;  &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The above jsp page is pretty simple. Notice that we have binded the value of &lt;br /&gt;inputText (to enter the country name) with selectedCountry variable in SelectedCountryRecord bean. The values of outputTexts (to display country information) are binded with the corresponding methods in SelectedCountryRecord bean to return the relevant information for the selected country.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112605310636955264?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112605310636955264/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112605310636955264' title='99 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112605310636955264'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112605310636955264'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/09/tutorial-using-ajax-in-jsf-application.html' title='Tutorial: Using Ajax in a JSF application - I'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>99</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112493685512906196</id><published>2005-08-24T19:30:00.000-07:00</published><updated>2005-09-06T17:34:20.356-07:00</updated><title type='text'>Using Ajax in a simple JSF Application - Introduction</title><content type='html'>I am going to start another tutorial on how to integrate Ajax with JSF soon. This is going to be a very simple JSF application with no GIS component. I hope that this could be of some help to GIS and non-GIS JSF developers alike.&lt;br /&gt;Before I talk about this application, here is a nice article that demonstrates how to create a JSF textbox component with auto-complete feature using Ajax technique:&lt;br /&gt;&lt;a href="https://bpcatalog.dev.java.net/ajax/textfield-jsf/design.html"&gt;https://bpcatalog.dev.java.net/ajax/textfield-jsf/design.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The above article discusses how to build a custom component that manages the necessary javascript code and can be easily used in a web page. I have, however, used a different approach to create a similar text box. It is simpler in a sense that it doesn't require you to create a custom TextBox component. The downside though is you will have to manage the Javascript code in the jsp page on your own. So if you do not mind writing/using the javascript code yourself, then you might want to give this a try.&lt;br /&gt;&lt;br /&gt;The application that I will be discussing will have a text box to enter a country name. As you type a new character in the text box, it will dynamically get upto 5 matching country names from the server and list those names for you to choose from. Once the text box has the selected country name and you submit the form, it will give you a brief description of that country.&lt;br /&gt;To accomplish the Ajax protion of the application, I have used the third strategy discussed in the following article:&lt;br /&gt;&lt;a href="https://bpcatalog.dev.java.net/nonav/ajax/jsf-ajax/frames.html"&gt;https://bpcatalog.dev.java.net/nonav/ajax/jsf-ajax/frames.html&lt;/a&gt;&lt;br /&gt;If you are a GIS Developer and have gone through my previous discussion on &lt;a href="http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server-i.html"&gt;Integrating Ajax with ArcGIS Server&lt;/a&gt;, the idea is pretty much the same.&lt;br /&gt;&lt;br /&gt;If you would like, you can download this application from &lt;a href="http://www.geocities.com/sekharkafle/jsfajax.zip"&gt;here&lt;/a&gt;. In order to run this application, simply extract the ajax folder from the zip file, put the JSF jar files in WEB-INF\lib folder and deploy it in a servlet container.&lt;br /&gt;&lt;br /&gt;Next time, I will discuss the code behind this application. Stay tuned!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112493685512906196?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112493685512906196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112493685512906196' title='18 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112493685512906196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112493685512906196'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/08/using-ajax-in-simple-jsf-application.html' title='Using Ajax in a simple JSF Application - Introduction'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>18</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112484436391861755</id><published>2005-08-23T18:42:00.000-07:00</published><updated>2005-08-24T15:28:50.936-07:00</updated><title type='text'>Hidden Input Element</title><content type='html'>HTML Hidden input element is typically used to transfer hidden data between the client and server. When writing a JSP or ASP application, you might have added a few hidden inputs to your page to persist the data between page reloads. With the evolution of server side technologies like .NET and JSF, the state of a control in the webpage is typically managed in the server side. It is, however, not efficient and sometimes almost impossible to put all data on the server and go back and forth between client and server for every user interaction. Say, for example, in a GIS web application, it would be impossible to post a request to the server to get the map coordinate every time you move the mouse on the map. Hence an efficient web application requires an optimum usage of client side and server side logic which in turn requires transferring the data back and forth between the server and client to make the two sides in synch with each other. The hidden input element can be handy in transferring such data. A typical example of using hidden input elements in a GIS application is passing the updated map extent (minx, miny, maxx, maxy values) between the server and the client.&lt;br /&gt;&lt;br /&gt;In my previous &lt;a href="http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server-iv.html"&gt;blog&lt;/a&gt;, I made use of a hidden input element to persist the web page state maintained in the client side. I helped a user with a similar problem using the hidden input element a while ago. This was in .NET. So I thought it would be nice to take a break from Java and talk about it.&lt;br /&gt;&lt;br /&gt;The problem was to enable/disable a tool item in the toolbar of the ArcGIS Server MapViewer template on the client side through Javascript without posting back the form immediately. The toolbar is managed by the .NET ADF on the server side. So if you simply change the property on the client side and do not somehow update the change on the server side, you will lose your change the next time your website is loaded. You can, of course, post back the form everytime you enable/disable a toolitem in the client side to synch the server with the client state. However, this means you need to post the form each time you make this change which is not an ideal solution. What would be an ideal solution is to use javascript to enable/disable the toolbar item and when the next time the form is posted, update the state of the toolbar to synch it with the client state.&lt;br /&gt;&lt;br /&gt;As mentioned before, we can make use of hidden input control run at the server side to do this. Lets discuss how we can customize the .NET MapViewer template to achieve this functionality:&lt;br /&gt;&lt;br /&gt;1. Add a hidden HTML input element to the Default page of the MapViewer template application. Set it to "Run as server Control". Make sure that this is added within the Form element in the HTML source.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Add an HTML Button to the page. We will use this button to test our function. Specify onclick="disableToolItem('ZoomOut');" for this button. This button when clicked calls disableToolItem function on the client side and does not post the form.&lt;br /&gt;&lt;br /&gt;3. Now lets take a look at disableToolItem function:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;function disableToolItem(toolItem){&lt;br /&gt; var f = document.forms[0];&lt;br /&gt; var listValues="";&lt;br /&gt; var Toolbar1 = Toolbars['Toolbar1'];&lt;br /&gt; var items1 = Toolbar1.Items;&lt;br /&gt; disableTool(toolItem, !items1[toolItem].Disabled, true);&lt;br /&gt;&lt;br /&gt; listValues += (items1['ZoomIn'].Disabled) ? "0":"1";&lt;br /&gt; listValues += (items1['ZoomOut'].Disabled) ? ":0":":1";&lt;br /&gt; listValues += (items1['Pan'].Disabled) ? ":0":":1";&lt;br /&gt; listValues += (items1['FullExtent'].Disabled) ? ":0":":1";&lt;br /&gt; listValues += (items1['ZoomBack'].Disabled) ? ":0":":1";&lt;br /&gt; listValues += (items1['ZoomNext'].Disabled) ? ":0":":1";&lt;br /&gt; listValues += (items1['Identify'].Disabled) ? ":0":":1";&lt;br /&gt; f.elements['activeToolList'].value = listValues;&lt;br /&gt; toolbarRefreshCommands('Toolbar1');&lt;br /&gt; //toolbarRefreshGroup('Toolbar1');&lt;br /&gt; toolbarSelectTool('Toolbar1');&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Notice that it first toggles the disable property of the given toolItem by calling the custom&lt;br /&gt;function disableTool (see below) and generates a String in&lt;br /&gt;this format: 0:1:1:1:0 where 0 and 1 represent the disabled&lt;br /&gt;and enabled state of the toolitem respectively. It then assigns this value&lt;br /&gt;to the hidden input element and refreshes the toolbar.&lt;br /&gt;&lt;br /&gt;4. The disableTool function is given below:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;function disableTool(itemName, disable, isTool ){&lt;br /&gt; var Toolbar1 = Toolbars['Toolbar1'];&lt;br /&gt; var items1 = Toolbar1.Items;&lt;br /&gt; items1[itemName].Disabled = disable;&lt;br /&gt; var cellName = 'Toolbar1' + itemName;&lt;br /&gt; var thisCellElement =&lt;br /&gt;    document.getElementById(cellName);&lt;br /&gt; if(disable){&lt;br /&gt;   thisCellElement.onmousedown == null;&lt;br /&gt;   thisCellElement.onmouseover == null;&lt;br /&gt;   thisCellElement.onmouseout == null;&lt;br /&gt; } else {&lt;br /&gt;   thisCellElement.onmousedown = function () {&lt;br /&gt;     if (isTool)&lt;br /&gt;     ToolbarMouseDown('Toolbar1', itemName, 'Tool');&lt;br /&gt;     else&lt;br /&gt;     ToolbarMouseDown('Toolbar1', itemName, 'Command');&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;   thisCellElement.onmouseover = function () {&lt;br /&gt;     ToolbarMouseOver('Toolbar1', itemName);&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;  thisCellElement.onmouseout = function () {&lt;br /&gt;    ToolbarMouseOut('Toolbar1', itemName);&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This function gets the specified toolbar item and nullifies the&lt;br /&gt;mouse events if disabling. It will activate the mouse events&lt;br /&gt;for toolbar item if enabling.&lt;br /&gt;&lt;br /&gt;5. Add the above functions to toolbar_functions.js file in C:\Inetpub\wwwroot\aspnet_client\esri_arcgis_server_webcontrols\9_1\JavaScript folder. &lt;span style="color:#ff0000;"&gt;(Be sure to keep a back up copy of the original file before you make any change to it.)&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;6. We need to modify the existing functions as follows:&lt;br /&gt;a) Find ToolbarMouseDown function in toolbar_functions.js file . Inside this function find&lt;br /&gt;this line:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var toolbar = Toolbars[toolbarName];&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Add this line after the above line:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if(toolbar.Items[toolbarItemName].Disabled) return;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;b) Inside ToolbarMouseOver function, find this line:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var toolbar = Toolbars[toolbarName];&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Add this line after the above line:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if(toolbar.Items[toolbarItemName].Disabled) return;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;c) Inside ToolbarMouseOut function, find this line:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var toolbar = Toolbars[toolbarName];&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Add this line after the above line:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if(toolbar.Items[toolbarItemName].Disabled) return;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;7. Finally, we need to update the server state when the page is posted back. Modify the Page_Load method of Default page as shown below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;private void Page_Load(object sender, System.EventArgs e)&lt;br /&gt; {&lt;br /&gt;   // Check parameters of MapControl&lt;br /&gt;   // If there is no Host or ServerObject defined,&lt;br /&gt;  // then there is no point to continuing since there will be no map to display&lt;br /&gt;  if ( (Map1.Host == null)  (Map1.Host == String.Empty) )&lt;br /&gt;  {&lt;br /&gt;   callErrorPage("Host property not defined for the Map control.", null);&lt;br /&gt;  }&lt;br /&gt;  if ( (Map1.ServerObject == null)&lt;br /&gt;          (Map1.ServerObject == String.Empty)&lt;br /&gt;          (Map1.ServerObject == "(none)") )&lt;br /&gt;  {&lt;br /&gt;   callErrorPage("ServerObject property not defined for the Map control.", null);&lt;br /&gt;  }&lt;br /&gt;  if (!Map1.AutoFirstDraw)&lt;br /&gt;  {&lt;br /&gt;   callErrorPage("The property AutoFirstDraw of&lt;br /&gt;          the Map WebControl must be set to true&lt;br /&gt;           for this application to run.", null);&lt;br /&gt;  }&lt;br /&gt;  // check if the server object can be accessed&lt;br /&gt; ESRI.ArcGIS.Server.WebControls.ServerConnection connection =&lt;br /&gt;            Map1.ServerConnection;&lt;br /&gt; if ( connection == null )&lt;br /&gt;   callErrorPage("Invalid ServerConnection.", null);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  // check if the server object is pooled&lt;br /&gt;  isPooled = connection.IsServerObjectPooled(Map1.ServerObject,"MapServer");&lt;br /&gt;&lt;br /&gt;  string activeTools="";&lt;br /&gt;  // Is this a PostBack or just started&lt;br /&gt;  if ( !Page.IsPostBack )&lt;br /&gt;  {&lt;br /&gt;   // Is this a new session?&lt;br /&gt;   if ( Session.IsNewSession )&lt;br /&gt;   {&lt;br /&gt;    // Save extent history to Session&lt;br /&gt;    m_extenthistory = new ArrayList();&lt;br /&gt;    m_extenthistory.Add(Map1.Extent);&lt;br /&gt;    Session.Add("extenthistory", m_extenthistory);&lt;br /&gt;    Session.Add("index",0);&lt;br /&gt;    m_lastextent = Map1.Extent;&lt;br /&gt;&lt;br /&gt;   //if new session, generate the string to store&lt;br /&gt;   //the enable/disable status of toomitems&lt;br /&gt;   //the value will be stored in 1:0:0:1:1 format&lt;br /&gt;   //where 1=enable, 0=disable&lt;br /&gt;&lt;br /&gt;   int toolLength = Toolbar1.ToolbarItems.Count;&lt;br /&gt;   for (int i=0;i&amp;lt;toolLength;i++)&lt;br /&gt;   {&lt;br /&gt;    string disableOrNot = "1";&lt;br /&gt;    Tool tool = Toolbar1.ToolbarItems[i] as Tool;&lt;br /&gt;    if(tool!=null)&lt;br /&gt;    {&lt;br /&gt;     if(tool.Disabled) disableOrNot = "0";&lt;br /&gt;     if(i==0) activeTools = disableOrNot;&lt;br /&gt;     else activeTools = activeTools + ":" + disableOrNot;&lt;br /&gt;    } else {&lt;br /&gt;     Command command1 = Toolbar1.ToolbarItems[i] as Command;&lt;br /&gt;     if(command1.Disabled) disableOrNot = "0";&lt;br /&gt;     if(i==0) activeTools = disableOrNot;&lt;br /&gt;     else activeTools = activeTools + ":" + disableOrNot;&lt;br /&gt;    }&lt;br /&gt;     //set the value to the hidden input control&lt;br /&gt;    activeToolList.Value = activeTools;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; } else {&lt;br /&gt;   //if not a new session&lt;br /&gt;   //get the values from the input control&lt;br /&gt;   //and update the toolitem property&lt;br /&gt;&lt;br /&gt;   activeTools = activeToolList.Value;&lt;br /&gt;   if((activeTools != "") &amp;&amp;amp; (activeTools != null))&lt;br /&gt;   {&lt;br /&gt;    char[] sep = {':'};&lt;br /&gt;    Array aa = activeTools.Split(sep);&lt;br /&gt;    for(int i = 0;i&amp;lt;aa.Length;i++)&lt;br /&gt;    {&lt;br /&gt;     Tool tool = Toolbar1.ToolbarItems[i] as Tool;&lt;br /&gt;     if(tool != null)&lt;br /&gt;     {&lt;br /&gt;      if (aa.GetValue(i).ToString()=="0") tool.Disabled = true;&lt;br /&gt;      else tool.Disabled=false;&lt;br /&gt;     }  else {&lt;br /&gt; Command command1 = Toolbar1.ToolbarItems[i] as Command;&lt;br /&gt; if (aa.GetValue(i).ToString()=="0") command1.Disabled = true;&lt;br /&gt; else command1.Disabled=false;&lt;br /&gt;     }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  // make sure that the session is still going, if not, display error page&lt;br /&gt;  if (Session["extenthistory"]==null)&lt;br /&gt;   callErrorPage("Your session has timed out.", null);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;  sessionId = Session.SessionID;&lt;br /&gt;  string scriptString = "\n&amp;lt;script language=javascript&amp;gt;sessionId = '"&lt;br /&gt;       + sessionId + "'; &amp;lt;/script&amp;gt;\n";&lt;br /&gt;  Page.RegisterStartupScript("SessionIdScript", scriptString);&lt;br /&gt;  // get name of session object holding map description&lt;br /&gt;  string pagePath = Page.Request.FilePath;&lt;br /&gt;  string pageName = "";&lt;br /&gt;  int lastSlash = pagePath.LastIndexOf("/");&lt;br /&gt;  if (lastSlash&gt;-1) pageName = pagePath.Substring(lastSlash+1);&lt;br /&gt;  m_MapDescriptSessName = pageName + Map1.ID + "_md";&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Notice above that when the new session is started, we get the toolitem property and&lt;br /&gt;generate the string to assign it to hidden input control. If this is not a new session but a postback request, we parse the value of hidden input control and update the property of the toolitem appropriately. This makes the state of the server toolbar in synch with that on the client side.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112484436391861755?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112484436391861755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112484436391861755' title='38 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112484436391861755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112484436391861755'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/08/hidden-input-element.html' title='Hidden Input Element'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>38</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112467587537503152</id><published>2005-08-21T20:40:00.000-07:00</published><updated>2005-08-21T20:41:50.950-07:00</updated><title type='text'>Integrating AJAX with ArcGIS Server - IV</title><content type='html'>In this final part of &lt;a href="http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server.html"&gt;Integrating AJAX with ArcGIS Server&lt;/a&gt; series, we will discuss how to customize javascript code for the custom magnifier tool. The most challenging part in this section is to integrate our custom tool in the existing toolbar managed by ArcGIS Server ADF. Java ADF manages the active tool through Map Control in the server side. The magnifier tool that we are developing, however, does not submit the request to ADF but to a separate servlet. So we need to develop our own mechanism to integrate this new tool to the existing toolbar. To solve this problem, we will add a JSF hidden input element to store the state (active or not) of the Magnifier tool and customize the javascript code to update the toolbar in client side. Since JSF components are stored in the server side, we will use this hidden input element to maintain the state of the magnifier tool between the postbacks.&lt;br /&gt;With this introduction, lets discuss the code step by step.&lt;br /&gt;&lt;br /&gt;1. We will be writing the javascript code in a separate file called ajax.js. So first thing we will do is add the reference to the js file in the mapviewer.jsp page:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  &amp;lt;script language="Javascript" src="js/ajax.js"&amp;gt;&lt;br /&gt;  &amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(We will take a look at this file in a while.)&lt;br /&gt;&lt;br /&gt;2. Add the magnifier tool right after the identify tool in the toolbar:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;td&amp;gt;            &lt;br /&gt;   &amp;lt;IMG id="imgMagnifier"&lt;br /&gt;           name="imgMagnifier"&lt;br /&gt;           src="images/magnifier.gif"&lt;br /&gt;           alt="Magnifier"&lt;br /&gt;           title="Magnifier"&lt;br /&gt;    onmouseover="this.src='images/magnifierU.gif'"&lt;br /&gt;    onmousedown="this.src='images/magnifierD.gif';&lt;br /&gt;             MapPoint('Map0', 'Magnifier');&lt;br /&gt;             HighlightTool('Magnifier');"&lt;br /&gt;    onmouseout="ButtonOut('imgMagnifier', 'Map0',&lt;br /&gt;            'Magnifier', 'images/magnifier.gif',&lt;br /&gt;            'images/magnifierD.gif');" /&amp;gt;&lt;br /&gt;  &amp;lt;jsfh:inputHidden id="btnMagnifierHidden" value="" /&amp;gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The above code is similar to other tools except these 2 important differences:&lt;br /&gt;a) In onmousedown event, we have called MapPoint function and passed our custom tool id called Magnifier. Since this is not the ADF managed tool but our own tool, we need to manage it through our custom javascript code. &lt;br /&gt;We will discuss the javascript code just in a bit.&lt;br /&gt;b) As mentioned before, we have added a jsf hidden input component to manage the status of the magnifier tool.&lt;br /&gt;&lt;br /&gt;3. Save the following images in images folder of the web application as magnifier.gif, magnifierU.gif and magnifierD.gif respectively:&lt;br /&gt;&lt;a href="http://photos1.blogger.com/blogger/6667/1038/1600/magnifier.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/blogger/6667/1038/200/magnifier.gif" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/blogger/6667/1038/1600/magnifierU.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/blogger/6667/1038/200/magnifierU.gif" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/blogger/6667/1038/1600/magnifierD.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/blogger/6667/1038/200/magnifierD.gif" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;4. Find the identifyResult control tag and add the following code right after it:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;div id="magnifierDiv"&lt;br /&gt;        style="position:absolute;&lt;br /&gt;        overflow:auto;&lt;br /&gt;        z-index:9999;&lt;br /&gt;        left:0px;&lt;br /&gt;        top:0px;&lt;br /&gt;        background-color:White;&lt;br /&gt;        border-style:ridge;&lt;br /&gt;        visibility:hidden;"&amp;gt;&lt;br /&gt;  &amp;lt;div id="mainImg"&amp;gt;&lt;br /&gt;   &amp;lt;IMG id="magnifierDivImg" src="" /&amp;gt;&lt;br /&gt;  &amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;div id="closeImg"&lt;br /&gt;    style="position:absolute;left:180px; top:5px;"&amp;gt;&lt;br /&gt;   &amp;lt;IMG id="magnifierCloseImg"&lt;br /&gt;           src="images/close.gif"&lt;br /&gt;           onmousedown="closeMagnifier();" /&amp;gt;&lt;br /&gt;  &amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In the above code, we have added a div element with 2 inner div elements. The first inner div element is to store the magnified image which would be obtained from our custom servlet. The second div element contains a close image which when clicked calls closeMagnifier() function to hide the magnifier div.&lt;br /&gt;&lt;br /&gt;5. Toward the end of the jsp file, find the script tag and modify it as shown below:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;script language="JavaScript"&amp;gt;&lt;br /&gt;var fid = document.forms[docFormID].id;&lt;br /&gt;&lt;br /&gt;var magnifierHidden = document.getElementById(fid+':btnMagnifierHidden');&lt;br /&gt;var mval = magnifierHidden.value;&lt;br /&gt;if(mval =="active"){&lt;br /&gt;document.images["imgMagnifier"].src = "images/magnifierD.gif";&lt;br /&gt;MapPoint('Map0', 'Magnifier');&lt;br /&gt;&lt;br /&gt;} else {&lt;br /&gt;HighlightTool(document.forms[docFormID].elements["Map0_mode"].value);&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;The above code checks the value of the hidden input element that we added. If its value is active (which means current active tool is magnifier), we will activate the magnifier tool. Otherwise it will behave in a normal manner.&lt;br /&gt;&lt;br /&gt;6. In the HighlighTool function:&lt;br /&gt;a) We need to add this line outside switch statement to unselect the magnifier tool:&lt;br /&gt;document.images["imgMagnifier"].src = "images/magnifier.gif";&lt;br /&gt;b) And this new case statement to select the magnifier tool:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;case "Magnifier":&lt;br /&gt;document.images["imgMagnifier"].src = "images/magnifierD.gif";&lt;br /&gt;break;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;7. Change the ButtonOut function to handle this new tool:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function ButtonOut(id, control, tool, flatimage, downimage)&lt;br /&gt;{&lt;br /&gt; var f = document.forms[docFormID];&lt;br /&gt; var m = control + "_mode";&lt;br /&gt; var mode = f.elements[m].value;&lt;br /&gt; var imgsrc = flatimage;&lt;br /&gt; var magVal = document.getElementById(f.id+':btnMagnifierHidden').value;&lt;br /&gt; if(magVal =="active"){&lt;br /&gt;  if(tool == "Magnifier") imgsrc = downimage;&lt;br /&gt; }else if (mode == tool) {&lt;br /&gt;  imgsrc = downimage;&lt;br /&gt; }&lt;br /&gt; var imgObj = document.getElementById(id);&lt;br /&gt; if(imgObj != null) imgObj.src = imgsrc;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;8. In map_functions.js file, find mapSetTool function and add this new variable right before&lt;br /&gt;this function:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var isMagnifier = false;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Add this new code at the top of the mapsetTool function:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var ff = document.forms[docFormID];&lt;br /&gt;var hid = document.getElementById(ff.id+':btnMagnifierHidden');&lt;br /&gt;if(mode=="Magnifier") {&lt;br /&gt;  //set the value of hidden input element&lt;br /&gt;  //to active&lt;br /&gt;  isMagnifier = true;&lt;br /&gt;  hid.value="active";&lt;br /&gt;  //change the cursor to crosshair&lt;br /&gt;  cursor="crosshair";&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;  isMagnifier = false;&lt;br /&gt;  //set empty value for hidden input element&lt;br /&gt;  hid.value="";&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In the above code, we are checking if Magnifier tool is activated. If so, we will set the value&lt;br /&gt;of isMagnifier to true and that of hidden input element to active. If any other tool has been selected, we set the value of isMagnifier to false and that of hidden input element to an empty value.&lt;br /&gt;&lt;br /&gt;9. Modify the mapPointClick function as shown below:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function mapPointClick(e) {&lt;br /&gt; if (isLeftButton(e)) {&lt;br /&gt;  getXY(e);&lt;br /&gt;  getMapDiv(e);&lt;br /&gt;  adjustMapCoords();&lt;br /&gt;  if(isMagnifier){&lt;br /&gt;     //call the custom function&lt;br /&gt;     sendMagnifierRequest (zleft, ztop);&lt;br /&gt;   }&lt;br /&gt;  else {&lt;br /&gt;     //post back the form&lt;br /&gt;     divObj.style.cursor = "wait";&lt;br /&gt;     var f = document.forms[docFormID];&lt;br /&gt;     f.minx.value=zleft;&lt;br /&gt;     f.miny.value=ztop;&lt;br /&gt;     postBack(Maps[divIndex].controlname, 'point');&lt;br /&gt;     //alert(divObj.id + "\n" + zleft + "," + ztop);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; return false;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here, we are calling our custom function (that we will be looking soon) instead of posting&lt;br /&gt; back the form if the magnifier tool is active.&lt;br /&gt;&lt;br /&gt;10. Now lets take a look at the ajax.js file:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var appName = "AjaxTest";&lt;br /&gt;&lt;br /&gt;function getHTTPObject() {&lt;br /&gt;    var xmlhttp;&lt;br /&gt;    //mozilla&lt;br /&gt;    if (window.XMLHttpRequest) {&lt;br /&gt;        xmlhttp = new XMLHttpRequest();&lt;br /&gt;    // IE&lt;br /&gt;    } else if (window.ActiveXObject) {&lt;br /&gt;        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt;    }&lt;br /&gt;    return xmlhttp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//XMLHttpRequest object&lt;br /&gt;var req ;&lt;br /&gt;&lt;br /&gt;//variables to store x/y location&lt;br /&gt;var ajx, ajy;&lt;br /&gt;&lt;br /&gt;//this function sends the request&lt;br /&gt;function sendMagnifierRequest(xx,yy) {&lt;br /&gt;   req = getHTTPObject();&lt;br /&gt;   ajx = mouseX;&lt;br /&gt;   ajy = mouseY;&lt;br /&gt; &lt;br /&gt;  //for IE, i needed to subtract 2 pixels&lt;br /&gt;  //to center the map more accurately&lt;br /&gt;  if(isIE){&lt;br /&gt;   xx -= 2;&lt;br /&gt;   yy -= 2;&lt;br /&gt;  }&lt;br /&gt;  var url = "/" + appName + "/AgsServlet?x=" + xx + "&amp;y=" + yy;&lt;br /&gt;  if (req != null) {&lt;br /&gt;    req.open("GET", url, true);&lt;br /&gt;    req.onreadystatechange = getResponse;&lt;br /&gt;    req.send(null);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//this function processes the response&lt;br /&gt;function getResponse(){&lt;br /&gt;&lt;br /&gt;if (req.readyState == 4) {&lt;br /&gt;    if (req.status == 200) {&lt;br /&gt;&lt;br /&gt;      var result = req.responseText;&lt;br /&gt;      //alert(result);&lt;br /&gt;      //position the div element&lt;br /&gt;       var mDiv = document.getElementById('magnifierDiv').style;&lt;br /&gt;       mDiv.left = ajx-100;&lt;br /&gt;       mDiv.top = ajy-100;&lt;br /&gt;       //specify the image returned as a src&lt;br /&gt;       var magImg = document.getElementById('magnifierDivImg');&lt;br /&gt;       magImg.src = result;&lt;br /&gt;       //show the div&lt;br /&gt;       mDiv.visibility = "visible";&lt;br /&gt;      &lt;br /&gt;    }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;//this function hides the div&lt;br /&gt;function closeMagnifier(){&lt;br /&gt; var mDiv = document.getElementById('magnifierDiv').style;&lt;br /&gt; mDiv.visibility = "hidden";&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;First we have specified the application name in a variable appName. Make sure to change&lt;br /&gt; this variable with your web application name.&lt;br /&gt;&lt;br /&gt;Function getHTTPObject creates and returns a new XMLHttPRequest object. Notice the difference in creating this object between IE and Mozilla.&lt;br /&gt;Function sendMagnifierRequest is responsible for submiting the user click point (x/y values) to our custom servlet. In this function, we first got a new XMLHttpRequest object called req and opened a "GET" connection to our custom Servlet. We have passed the x/y values to the servlet by appending the argument value pair to the url. The following line specifies that getReponse function will be called every time he state of XMLHttpRequest object is changed:&lt;br /&gt;req.onreadystatechange = getResponse;&lt;br /&gt;&lt;br /&gt;Remember that one of the key features in Ajax is to send requests asynchronously, i.e. we won't be sitting there and waiting for the response once we submit the request. That is why we have specified the above function that will track the state of the XMLHttpRequest object and processes the response when ready.&lt;br /&gt;&lt;br /&gt;In the getResponse function, we will check the state of the XMLHTTPRequest object and if it's value is 4 (i.e. completed) and the HTTP status of the response is 200 (OK), we will then process the response.&lt;br /&gt;Remember from our previous discussion, the custom servlet simply sends back the url of the output image in a simple text format. So we will get this url from responseText property of the req object and set the url as a source to an image in a div element. We will center this DIV element at the click location and finally make it visible.&lt;br /&gt;&lt;br /&gt;11. Finally, save the ajax.js file in the js folder of your web application.&lt;br /&gt;Thats it. You are all set to test this new tool. Enjoy!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112467587537503152?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112467587537503152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112467587537503152' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112467587537503152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112467587537503152'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server-iv.html' title='Integrating AJAX with ArcGIS Server - IV'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112442818736273138</id><published>2005-08-18T22:45:00.000-07:00</published><updated>2005-08-18T22:47:29.086-07:00</updated><title type='text'>Integrating AJAX with ArcGIS Server - III</title><content type='html'>&lt;a href="http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server-ii.html"&gt;Previously&lt;/a&gt;, we have looked at the necessary code for our custom magnifier tool. Now lets talk about how to put things together step by step.&lt;br /&gt;1. First, use arcgisant tool to create a MapViewer web application.&lt;br /&gt;2. Deploy the web application in a servlet container and verify that it works fine.&lt;br /&gt;3. Go to this web application root directory and then to its WEB-INF/classes folder.&lt;br /&gt;4. Under the classes folder, create this path: com/esri/arcgis/sample.&lt;br /&gt;5. Put the &lt;a href="http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server-i.html"&gt;AgsServlet.java&lt;/a&gt; and &lt;a href="http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server-ii.html"&gt;AgsMap.java&lt;/a&gt; files in the sample folder.&lt;br /&gt;6. Compile these 2 java classes. (You need to have servlet and arcgis server libraries in the classpath to compile the code.)&lt;br /&gt;7. Next, we need to map our custom servlet in the web application. Go to WEB-INF folder and open web.xml file.&lt;br /&gt;a) Add these tags to add the servlet:&lt;br /&gt;&lt;br /&gt;&amp;lt;servlet&amp;gt;&lt;br /&gt;&amp;lt;servlet-name&amp;gt;AgsServlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;&amp;lt;servlet-class&amp;gt;com.esri.arcgis.sample.AgsServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;&amp;lt;/servlet&amp;gt;&lt;br /&gt;&lt;br /&gt;b) Add these tags to map the servlet:&lt;br /&gt;&amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;&amp;lt;servlet-name&amp;gt;AgsServlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;&amp;lt;url-pattern&amp;gt;/AgsServlet&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;&amp;lt;/servlet-mapping&amp;gt;&lt;br /&gt;&lt;br /&gt;8. Refresh the servlet container.&lt;br /&gt;&lt;br /&gt;This does it for the configuration of our custom servlet in the web application. Next time, we will talk about how to add the magnifier tool to the jsp page and customize the javascript code for this new tool.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112442818736273138?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112442818736273138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112442818736273138' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112442818736273138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112442818736273138'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server.html' title='Integrating AJAX with ArcGIS Server - III'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112424687491965871</id><published>2005-08-16T23:06:00.000-07:00</published><updated>2005-08-18T22:10:26.103-07:00</updated><title type='text'>Integrating AJAX with ArcGIS Server - II</title><content type='html'>Now lets take a look at AGSMap class mentioned &lt;a href="http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server-i.html"&gt;earlier&lt;/a&gt;. Given below is the complete code for this class. Since I have added comments in between the code describing each part of the code, this should be self explanatory.&lt;pre&gt;&lt;br /&gt;package com.esri.arcgis.sample;&lt;br /&gt;&lt;br /&gt;import com.esri.arcgis.server.IServerConnection;&lt;br /&gt;import com.esri.arcgis.server.ServerConnection;&lt;br /&gt;import com.esri.arcgis.server.IServerObjectManager;&lt;br /&gt;import com.esri.arcgis.server.IServerContext;&lt;br /&gt;&lt;br /&gt;import com.esri.arcgis.carto.IMapServer;&lt;br /&gt;import com.esri.arcgis.carto.IMapServerProxy;&lt;br /&gt;import com.esri.arcgis.carto.IMapDescription;&lt;br /&gt;import com.esri.arcgis.carto.IMapServerObjects;&lt;br /&gt;import com.esri.arcgis.carto.IMapServerObjectsProxy;&lt;br /&gt;import com.esri.arcgis.carto.IMap;&lt;br /&gt;import com.esri.arcgis.carto.IMapProxy;&lt;br /&gt;import com.esri.arcgis.carto.IMapDescriptionProxy;&lt;br /&gt;import com.esri.arcgis.carto.MapDescription;&lt;br /&gt;import com.esri.arcgis.carto.IImageDescription;&lt;br /&gt;import com.esri.arcgis.carto.IImageDescriptionProxy;&lt;br /&gt;import com.esri.arcgis.carto.ImageDescription;&lt;br /&gt;import com.esri.arcgis.carto.IImageType;&lt;br /&gt;import com.esri.arcgis.carto.IImageTypeProxy;&lt;br /&gt;import com.esri.arcgis.carto.ImageType;&lt;br /&gt;import com.esri.arcgis.carto.IImageDisplay;&lt;br /&gt;import com.esri.arcgis.carto.IImageDisplayProxy;&lt;br /&gt;import com.esri.arcgis.carto.ImageDisplay;&lt;br /&gt;import com.esri.arcgis.carto.IMapImage;&lt;br /&gt;import com.esri.arcgis.carto.IMapImageProxy;&lt;br /&gt;import com.esri.arcgis.carto.MapImage;&lt;br /&gt;import com.esri.arcgis.carto.IMapExtent;&lt;br /&gt;import com.esri.arcgis.carto.IMapExtentProxy;&lt;br /&gt;import com.esri.arcgis.carto.MapExtent;&lt;br /&gt;import com.esri.arcgis.carto.IMapArea;&lt;br /&gt;import com.esri.arcgis.carto.IMapAreaProxy;&lt;br /&gt;import com.esri.arcgis.carto.esriImageFormat;&lt;br /&gt;import com.esri.arcgis.carto.esriImageReturnType;&lt;br /&gt;import com.esri.arcgis.carto.IImageResult;&lt;br /&gt;&lt;br /&gt;import com.esri.arcgis.system.LongArray;&lt;br /&gt;import com.esri.arcgis.system.ILongArray;&lt;br /&gt;import com.esri.arcgis.system.ILongArrayProxy;&lt;br /&gt;&lt;br /&gt;import com.esri.arcgis.geometry.IPoint;&lt;br /&gt;import com.esri.arcgis.geometry.IPointCollection;&lt;br /&gt;import com.esri.arcgis.geometry.IEnvelope;&lt;br /&gt;import com.esri.arcgis.geometry.Envelope;&lt;br /&gt;import com.esri.arcgis.geometry.IEnvelopeProxy;&lt;br /&gt;&lt;br /&gt;import com.esri.arcgis.webcontrols.ags.data.*;&lt;br /&gt;&lt;br /&gt;public class AgsMap {&lt;br /&gt;&lt;br /&gt;  public synchronized static String&lt;br /&gt;    getImageUrl(AGSWebContext context, int x, int y){&lt;br /&gt;   try{&lt;br /&gt;     //get IMapServer from AGSWebContext&lt;br /&gt;     IMapServer m_mapServer = context.getServer();&lt;br /&gt;     //QI to IMapServerObjects&lt;br /&gt;     IMapServerObjects m_mapServerObj =&lt;br /&gt;        new IMapServerObjectsProxy(m_mapServer);&lt;br /&gt;     // get IServerContext from AGSWebContext&lt;br /&gt;     IServerContext m_context = context.getServerContext();&lt;br /&gt;   &lt;br /&gt;     IMap m_map = null;&lt;br /&gt;     //if there is a default map, get IMap&lt;br /&gt;     if (m_mapServer.getDefaultMapName() != null) {&lt;br /&gt;       m_map = new IMapProxy(m_mapServerObj.getMap(&lt;br /&gt;                m_mapServer.getDefaultMapName()));&lt;br /&gt;     } else return null;&lt;br /&gt;&lt;br /&gt;     //get Default MapDescription from AGSWebContext&lt;br /&gt;     IMapDescription m_mapDesc = context.getMapDescription(&lt;br /&gt;                m_mapServer.getDefaultMapName());&lt;br /&gt;     /*&lt;br /&gt;       create a new ImageType and set the properties&lt;br /&gt;       we are getting the image url, so make sure to&lt;br /&gt;       specify output directory in ArcCatalog&lt;br /&gt;       for the server object config being used in&lt;br /&gt;       this application&lt;br /&gt;     */ &lt;br /&gt;     IImageType m_imageType = new IImageTypeProxy(&lt;br /&gt;                m_context.createObject(ImageType.getClsid()));&lt;br /&gt;      m_imageType.setFormat(esriImageFormat.esriImagePNG);&lt;br /&gt;      m_imageType.setReturnType(&lt;br /&gt;               esriImageReturnType.esriImageReturnURL);&lt;br /&gt;&lt;br /&gt;      //create a new IImageDisplay&lt;br /&gt;      //set width and height same as that of the Map Control&lt;br /&gt;      //because we will be using it to convert pixel&lt;br /&gt;      //point to Map point&lt;br /&gt;      IImageDisplay m_imageDisplay = new IImageDisplayProxy(&lt;br /&gt;            m_context.createObject(ImageDisplay.getClsid()));&lt;br /&gt;      m_imageDisplay.setDeviceResolution(96D);&lt;br /&gt;      m_imageDisplay.setWidth(context.getWebMap().getWidth());&lt;br /&gt;      m_imageDisplay.setHeight(context.getWebMap().getHeight());&lt;br /&gt;&lt;br /&gt;      //set the above IImageDisplay and IImageType&lt;br /&gt;      //  to IImageDescription&lt;br /&gt;      IImageDescription m_imageDesc = new IImageDescriptionProxy(&lt;br /&gt;             m_context.createObject(ImageDescription.getClsid()));&lt;br /&gt;      m_imageDesc.setDisplay(m_imageDisplay);&lt;br /&gt;      m_imageDesc.setType(m_imageType);&lt;br /&gt;&lt;br /&gt;      //convert pixel point into map point&lt;br /&gt;      //notice that we are using the above map&lt;br /&gt;      //description and image description&lt;br /&gt;      // in mapserver.toMapPoints method&lt;br /&gt;      ILongArray longArrayX = new ILongArrayProxy(&lt;br /&gt;             m_context.createObject(LongArray.getClsid()));&lt;br /&gt;      longArrayX.insert(0, x-10);&lt;br /&gt;      ILongArray longArrayY = new ILongArrayProxy(&lt;br /&gt;             m_context.createObject(LongArray.getClsid()));&lt;br /&gt;      longArrayY.insert(0, y+10);&lt;br /&gt;      longArrayX.insert(1,x+10);&lt;br /&gt;      longArrayY.insert(1,y-10);&lt;br /&gt;      IPointCollection pointColl = m_mapServer.toMapPoints(&lt;br /&gt;                         m_mapDesc,&lt;br /&gt;                         m_imageDesc.getDisplay(),&lt;br /&gt;                        longArrayX,&lt;br /&gt;                        longArrayY);&lt;br /&gt;      IPoint point1 = null;&lt;br /&gt;      IPoint point2 = null;&lt;br /&gt;      if (pointColl.getPointCount() &gt; 0) {&lt;br /&gt;       point1 = pointColl.getPoint(0);&lt;br /&gt;       point2 = pointColl.getPoint(1);&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      //generate a small envelope based on map points&lt;br /&gt;      IEnvelope env = new IEnvelopeProxy(&lt;br /&gt;            m_context.createObject(Envelope.getClsid()));&lt;br /&gt;      env.setXMin(point1.getX());&lt;br /&gt;      env.setYMin(point1.getY());&lt;br /&gt;      env.setXMax(point2.getX());&lt;br /&gt;      env.setYMax(point2.getY());&lt;br /&gt;&lt;br /&gt;      //reset the Image size to 200X200&lt;br /&gt;      //this is the size of the magnified image&lt;br /&gt;      m_imageDesc.getDisplay().setWidth(200);&lt;br /&gt;      m_imageDesc.getDisplay().setHeight(200);&lt;br /&gt;&lt;br /&gt;      //set the new MapExtent based on the above envelope&lt;br /&gt;      IMapExtent mapExtent = new IMapExtentProxy(&lt;br /&gt;          m_context.createObject(MapExtent.getClsid()));&lt;br /&gt;      mapExtent.setExtent(env);&lt;br /&gt;&lt;br /&gt;      //create a new map description and set above&lt;br /&gt;      //extent and default LayerDescriptions to it&lt;br /&gt;      IMapDescription m_mapDesc1 = new IMapDescriptionProxy(&lt;br /&gt;         m_context.createObject(MapDescription.getClsid()));&lt;br /&gt;      IMapArea mapArea = new IMapAreaProxy(mapExtent);&lt;br /&gt;      m_mapDesc1.setMapArea(mapArea);&lt;br /&gt;      m_mapDesc1.setLayerDescriptions(&lt;br /&gt;                 m_mapDesc.getLayerDescriptions());&lt;br /&gt;      m_mapDesc1.setName(m_mapServer.getDefaultMapName());&lt;br /&gt;&lt;br /&gt;      //export the map image and get its URL&lt;br /&gt;      IMapImage mapImage = m_mapServer.exportMapImage(&lt;br /&gt;              m_mapDesc1, m_imageDesc);&lt;br /&gt;      String url = mapImage.getURL();&lt;br /&gt;      //finally release the context&lt;br /&gt;      m_context.removeAll();&lt;br /&gt;      m_context.releaseContext();&lt;br /&gt;      return url;&lt;br /&gt;     }catch (Exception ex){&lt;br /&gt;        ex.printStackTrace();&lt;br /&gt;        return null;&lt;br /&gt;     }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112424687491965871?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112424687491965871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112424687491965871' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112424687491965871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112424687491965871'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server-ii.html' title='Integrating AJAX with ArcGIS Server - II'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112417402315915653</id><published>2005-08-16T20:10:00.000-07:00</published><updated>2005-08-18T22:10:48.840-07:00</updated><title type='text'>Integrating AJAX with ArcGIS Server - I</title><content type='html'>As I mentioned &lt;a href="http://kafle.blogspot.com/2005/08/ajaxizing-arcgis-server-mapviewer.html"&gt;previously&lt;/a&gt;, one of the ways to implement Ajax in the ArcGIS Server Java application is by creating a custom Servlet. We can then write Javascript code to submit client request to this custom Servlet using the XMLHttpRequest object. The servlet in return will generate the response which is again processed by the custom Javascript code on the client side.&lt;br /&gt;&lt;br /&gt;Lets talk about how to create a Magnifier tool in ArcGIS Server MapViewer template by creating a custom servlet. First, we will pass the user click point (X/Y values) to our custom servlet. The custom Servlet will then use ArcObjects to generate the magnified image for that location. That sounds easy, but how can we get the server object properties (like server connection, map properties etc.) already stored in Java ADF in our custom Servlet? They are required for us to be able generate the map image using our custom ArcObjects code. The answer is the AGSWebContext object which hosts all ArcObjects for the server object.&lt;br /&gt;&lt;br /&gt;Getting AGSWebContext in a Servlet is pretty simple. All we need to do is first get the WebSession attribute from session and then get AGSWebContext object from WebSession. Once we get AGSWebContext object, we need to&lt;br /&gt;1. call activate method to hydrate the current properties of a pooled server object. (We are using pooled server object because we want to be able to quickly generate image and release the server object back. )&lt;br /&gt;2. pass the AgsWebContext to another class names AgsMap which will generate the image.&lt;br /&gt;3. call passivate method to release the server object back to the pool.&lt;br /&gt;&lt;br /&gt;I will discuss the AgsMap class next time but for now here is the complete code for the custom Servlet:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package com.esri.arcgis.sample;&lt;br /&gt;&lt;br /&gt;import javax.servlet.ServletConfig;&lt;br /&gt;import javax.servlet.ServletException;&lt;br /&gt;import javax.servlet.http.HttpServlet;&lt;br /&gt;import javax.servlet.http.HttpServletRequest;&lt;br /&gt;import javax.servlet.http.HttpServletResponse;&lt;br /&gt;import javax.servlet.http.HttpSession;&lt;br /&gt;&lt;br /&gt;import com.esri.arcgis.webcontrols.ags.data.*;&lt;br /&gt;import com.esri.arcgis.webcontrols.data.*;&lt;br /&gt;&lt;br /&gt;public final class AgsServlet&lt;br /&gt;  extends HttpServlet {&lt;br /&gt;&lt;br /&gt;   private ServletConfig servletConfig = null;&lt;br /&gt;&lt;br /&gt;    public void destroy() {&lt;br /&gt;        servletConfig = null;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public ServletConfig getServletConfig() {&lt;br /&gt;&lt;br /&gt;        return (this.servletConfig);&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getServletInfo() {&lt;br /&gt;&lt;br /&gt;        return (this.getClass().getName());&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void init(ServletConfig servletConfig)&lt;br /&gt;      throws ServletException {&lt;br /&gt;&lt;br /&gt;        this.servletConfig = servletConfig;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void doGet(HttpServletRequest request,&lt;br /&gt;      HttpServletResponse response)&lt;br /&gt;       throws java.io.IOException, ServletException {&lt;br /&gt;         HttpSession session = request.getSession(true);&lt;br /&gt;         int x = Integer.parseInt(&lt;br /&gt;                  (String)request.getParameter("x"));&lt;br /&gt;         int y = Integer.parseInt(&lt;br /&gt;                  (String)request.getParameter("y"));&lt;br /&gt;         WebSession wsession = (WebSession)&lt;br /&gt;           session.getAttribute(WebSession.SESSION_ATTRIBUTE_NAME );&lt;br /&gt;         String url=null;&lt;br /&gt;         if(wsession!=null) {&lt;br /&gt;           AGSWebContext context = (AGSWebContext)&lt;br /&gt;                wsession.findWebContext(0);&lt;br /&gt;           context.activate();&lt;br /&gt;           url = AgsMap.getImageUrl(context, x, y);&lt;br /&gt;           context.passivate();&lt;br /&gt;         }&lt;br /&gt;         response.setContentType("text/html");&lt;br /&gt;         java.io.PrintWriter out=response.getWriter();&lt;br /&gt;         out.print(url);&lt;br /&gt;         out.flush();&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public void doPost(HttpServletRequest request,&lt;br /&gt;       HttpServletResponse response)&lt;br /&gt;          throws java.io.IOException, ServletException {&lt;br /&gt;             doGet(request, response);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112417402315915653?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112417402315915653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112417402315915653' title='279 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112417402315915653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112417402315915653'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/08/integrating-ajax-with-arcgis-server-i.html' title='Integrating AJAX with ArcGIS Server - I'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>279</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112414020076907192</id><published>2005-08-14T23:14:00.000-07:00</published><updated>2005-08-15T14:12:34.093-07:00</updated><title type='text'>AJAXizing ArcGIS Server MapViewer Template</title><content type='html'>Being a great Ajax fan, I am excited to see big companies like Google, Microsoft, Oracle, Sun promoting it big time. ESRI is also planning to implement Ajax in the 9.2 Server ADF. I have developed a few tools myself integrating Ajax with the current ArcGIS Server MapViewer Java template and I think it's really cool and fast.&lt;br /&gt;Let me describe one such tool a little bit more. It is the magnifier tool just like in ArcMap to get the more detailed floating map for a particular location in the main map. Normally with the server applications, you need to submit the form and reload the entire webpage to get the new data. Using the Ajax technique, however, we can request the magnified map behind the scene and thus it will eliminate the need to reload the entire website. Since there is no need to render the entire website, which could be costly timewise, there will be a significant improvement in performance and thus the user experience will be much closer to that of the desktop applications.&lt;br /&gt;&lt;a href="https://bpcatalog.dev.java.net/nonav/ajax/jsf-ajax/frames.html"&gt;Greg Murray, Tor Norbye, Ed Burns &lt;/a&gt;have described 3 different techniques to use JSF application like the ArcGIS Server MapViewer with ajax. The first 2 techniques require creating custom components in JSF in such a way that the users of such components need not implement their own javascript code. &lt;a href="http://blogs.sun.com/roller/page/tor/20050731"&gt;Tor Norbye&lt;/a&gt; has described the design detail for creating an Ajax auto-complete component &lt;a href="https://bpcatalog.dev.java.net/ajax/textfield-jsf/design.html"&gt;here&lt;/a&gt;.&lt;br /&gt;I have, however, used the third technique because of its simplicity. With this technique, I didn't need to create my own custom JSF components. I had rather created a custom Servlet that would be responsible for generating the response for each request.&lt;br /&gt;In my upcoming blogs, I will describe the code behind this tool.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112414020076907192?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112414020076907192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112414020076907192' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112414020076907192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112414020076907192'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/08/ajaxizing-arcgis-server-mapviewer.html' title='AJAXizing ArcGIS Server MapViewer Template'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112408355098133132</id><published>2005-08-14T22:28:00.000-07:00</published><updated>2005-08-18T18:13:36.253-07:00</updated><title type='text'>Remote ArcIMS server in a frameless html viewer</title><content type='html'>There have been some questions about how to run &lt;a href="http://arcscripts.esri.com/details.asp?dbid=14104"&gt;Frameless HTML Viewer&lt;/a&gt; in a separate web server and access a remote ArcIMS Server from it. Javascript has the same origin policy which prevents a webpage loaded from one server communicating to a different server for security reason. To work around this problem in the HTML Viewer, there is a property in the Servlet Connector called redirect which allows forwarding the ArcXML requests to the remote ArcIMS server. Thus by installing the Servlet Connector on a web server and setting it to redirect to any remote server, we can 'fool' the Javascript to think that it's loading the response from the same server.&lt;br /&gt;I initially thought this would work for the frameless viewer too. On further testing, it appeared that the redirection in servlet connector works only with the form based requests.&lt;br /&gt;There is still another work around though. This is to create a web application in jsp/ASP/Servlet etc and deploy it on the web server. The web application needs to simply forward the ArcXML requests to the remote ArcIMS Server and get back the responses. It is pretty simple to create such application using one of the connectors.&lt;br /&gt;For instance, here is the JSP code to do this:&lt;br /&gt;&lt;br /&gt;&amp;lt;%@ page import="java.util.*" %&amp;gt;&lt;br /&gt;&amp;lt;%@ page import="java.io.*" %&amp;gt;&lt;br /&gt;&amp;lt;%@ page import="com.esri.aims.mtier.io.ConnectionProxy" %&amp;gt;&lt;br /&gt;&amp;lt;%&lt;br /&gt;String server = "http://www.geographynetwork.com";&lt;br /&gt;String service = "ESRI_World";&lt;br /&gt;ConnectionProxy mcp = new ConnectionProxy();&lt;br /&gt;mcp.setConnectionType(ConnectionProxy.HTTP);&lt;br /&gt;mcp.setService(service);&lt;br /&gt;mcp.setUrl(new java.net.URL(server));&lt;br /&gt;int reqLength = request.getContentLength();&lt;br /&gt;byte[] reqByte;&lt;br /&gt;if (reqLength &amp;gt; 0) {&lt;br /&gt;reqByte = new byte[reqLength];&lt;br /&gt;int data = 1;&lt;br /&gt;int offset = 0;&lt;br /&gt;while (data &amp;gt; 0) {&lt;br /&gt;data = request.getInputStream().read(reqByte, offset,reqLength - offset);&lt;br /&gt;offset = offset+ data;&lt;br /&gt;}&lt;br /&gt;String axl = new String(reqByte);&lt;br /&gt;String res = mcp.send(axl);&lt;br /&gt;out.println(res);&lt;br /&gt;} else&lt;br /&gt;out.println("Error");&lt;br /&gt;%&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112408355098133132?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112408355098133132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112408355098133132' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112408355098133132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112408355098133132'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/08/remote-arcims-server-in-frameless-html.html' title='Remote ArcIMS server in a frameless html viewer'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12321538.post-112388801031242587</id><published>2005-08-12T21:05:00.000-07:00</published><updated>2005-08-12T16:39:07.186-07:00</updated><title type='text'>Ajax and HTML Viewer</title><content type='html'>I have lately been playing around with JSF and Ajax. I will be writing more on these topics soon. For now though, a little bit on Ajax.&lt;br /&gt;Ajax, if you do not know about it yet, is a concept rather than a tool. Using a little known (until recently) Javascript object called XMLHTTPRequest, one can send asynchronous requests to the server and get data in the background so that the web content can be updated dynamically without the need to reload the entire website. There are other things about ajax and you can get more descriptions here:&lt;br /&gt;&lt;a href="http://www.adaptivepath.com/publications/essays/archives/000385.php"&gt;&lt;span style="font-size:85%;"&gt;http://www.adaptivepath.com/publications/essays/archives/000385.php&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Think about it, ArcIMS HTML Viewer is partially (of course, not completely) an ajax application too. Just like a typical ajax application, it receives the data from the server in the background and updates the webpages dynamically. There is no reloading of the entire website for each and every requests. Of course, it uses frames to achieve this.&lt;br /&gt;Many ArcIMS developers have wondered about how to create a frameless HTML Viewer. Ajax is the way to go and here is a sample application:&lt;br /&gt;&lt;a href="http://arcscripts.esri.com/details.asp?dbid=14104"&gt;http://arcscripts.esri.com/details.asp?dbid=14104&lt;/a&gt;&lt;br /&gt;Here is one more example of ajax in action:&lt;br /&gt;&lt;a href="http://arcscripts.esri.com/details.asp?dbid=14110"&gt;http://arcscripts.esri.com/details.asp?dbid=14110&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12321538-112388801031242587?l=kafle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kafle.blogspot.com/feeds/112388801031242587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12321538&amp;postID=112388801031242587' title='114 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112388801031242587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12321538/posts/default/112388801031242587'/><link rel='alternate' type='text/html' href='http://kafle.blogspot.com/2005/08/ajax-and-html-viewer.html' title='Ajax and HTML Viewer'/><author><name>S Kafle</name><uri>http://www.blogger.com/profile/13722424647743825352</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>114</thr:total></entry></feed>
