The buttons and tools of the same type are combined to form a logical unit, which is tasks. Like tools, tasks is also a common Java class.
Writing a task can be divided into the following steps:
1. Compile the task class, including the command or tool to be used.
2. Compile the taskinfo class and configure the attributes of task commands and parameters.
3. Configure in faces-config.xml
4. Make a call on the page
This document records the process of writing a task, which includes a text query function (including parameters) and a drop-down box amplification function.
1: Compile the task class
Task class package COM. demo; import Java. util. collection; import Java. util. list; import Java. util. map; import COM. ESRI. ADF. web. AGS. data. agsmapresource; import COM. ESRI. ADF. web. data. webcontext; import COM. ESRI. ADF. web. data. geometry. webextent; import COM. ESRI. ADF. web. data. geometry. webgeometry; import COM. ESRI. ADF. web. data. query. queryresult; import COM. ESRI. ADF. web. data. query. textcriteria; import COM. ESRI. ADF. web. data. query. webquery; import COM. ESRI. ADF. web. faces. event. mapevent; import COM. ESRI. ADF. web. faces. event. taskevent;/*** no need to implement other interfaces for Testing task */public class mytask {// string parameter, a parameter required for text query, Public String getparameter () {return parameter ;} public void setparameter (string parameter) {This. parameter = parameter;}/*** text query * does not interact with the map. The parameter is taskevent */Public void query (taskevent event) {webcontext context = event. getwebcontext (); agsmapresource res = (agsmapresource) context. getresources (). get ("agsws1"); textcriteria Tc = new textcriteria (); TC. setsearchtext (this. parameter); webquery query = (webquery) context. getattribute ("query"); List layer = context. getwebquery (). getquerylayers (); List Results = query. query (TC, layer); For (INT I = 0; I <results. size (); I ++) {queryresult result = (queryresult) results. get (I); result. highlight (); map = result. getdetails (); map. size (); Collection Col = map. values (); object [] OBJ = Col. toarray (); For (Int J = 0; j <obj. length; j ++) {system. out. println (OBJ [J]) ;}}/*** zoom in with the map interaction * with the map interaction parameter mapevent */Public void zoomin (mapevent Te) {webcontext CTX = tE. getwebcontext (); webgeometry Geom = tE. getwebgeometry (). tomapgeometry (CTX. getwebmap (); webextent ext = (webextent) Geom; CTX. getwebmap (). setcurrentextent (EXT); CTX. refresh ();}}
2: Compile the taskinfo class:
Taskinfo class package COM. demo; import COM. ESRI. ADF. web. data. tasks. simpletaskinfo; import COM. ESRI. ADF. web. data. tasks. taskactiondescriptor; import COM. ESRI. ADF. web. data. tasks. taskactiondescriptormodel; import COM. ESRI. ADF. web. data. tasks. taskdescriptor; import COM. ESRI. ADF. web. data. tasks. taskparamdescriptor; import COM. ESRI. ADF. web. data. tasks. taskparamdescriptormodel; import COM. ESRI. ADF. web. data. tasks. tasktooldescriptor; import COM. ESRI. ADF. web. data. tasks. tasktooldescriptormodel; import COM. ESRI. ADF. web. faces. event. clientactions;/*** the taskinfo class of mytask * inherits from simpletaskinfo, override method to set the parameters */public class mytaskinfo extends simpletaskinfo {/*** set the task name */Public taskdescriptor gettaskdescriptor () {taskdescriptor TD = new taskdescriptor (mytask. class); TD. setdisplayname ("My tasks"); Return TD;}/*** set the tool type button parameter * override the gettooldescriptors Method */Public tasktooldescriptormodel [] gettooldescriptors () {tasktooldescriptor [] tooldesary = newtasktooldescriptor [1]; // set the display name of the enlarged tool and the client action type tasktooldescriptor tooldesc = new tasktooldescriptor (mytask. class, "zoomin", "Interactive amplification", clientactions. map_rectangle); tooldesary [0] = tooldesc; return tooldesary;}/*** set the command type button parameter * override the getactiondescriptors Method */Public taskactiondescriptormodel [] getactiondescriptors () {taskactiondescriptormodel [] TD = new taskactiondescriptormodel [1]; // set the display name of the query command taskactiondescriptormodel actiondesc = new taskactiondescriptor (mytask. class, "query", "query"); TD [0] = actiondesc; return TD ;} /*** set the display name of each parameter * override the getparamdescriptors Method */Public taskparamdescriptormodel [] getparamdescriptors () {taskparamdescriptormodel [] TD = new taskparamdescriptormodel [1]; // set the display name of the parameters required for the query. taskparamdescriptormodel paradesc = new taskparamdescriptor (mytask. class, "parameter", "query text"); TD [0] = paradesc; return TD ;}}
3: Configure in faces-config.xml
Query -- configure <managed-bean> <managed-bean-Name> mapcontext </managed-bean-Name> <managed-bean-class> COM. ESRI. ADF. web. data. webcontext </managed-bean-class> <managed-bean-scope> request </managed-bean-scope> <managed-property> <property-Name> attributes </property- name> <map-entries> <map-entry> <key> query </key> <value >#{ webappquery} </value> </Map-entry> <map- entry> <key> graphics </key> <value >#{ graphics} </value> </Ma P-entry>... <! -- Webquery declaration --> <managed-bean-Name> webappquery </managed-bean-Name> <managed-bean-class> COM. ESRI. ADF. web. data. query. webquery </managed-bean-class> <managed-bean-scope> none </managed-bean-scope> <managed-property> <property-Name> layerdefinitions </property- name> <list-entries> <value >#{ arcgis_localmapgrid2_usa_2d_v_layer1} </value> .... </list-entries> </managed-property> </managed-bean>
<managed-bean>
<managed-bean-name>MyTask</managed-bean-name>
<managed-bean-class>com.demo.MyTask</managed-bean-class>
<managed-bean-scope>session </managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>MyTaskInfo</managed-bean-name>
<managed-bean-class>com.demo.MyTaskInfo</managed-bean-class>
<managed-bean-scope>session </managed-bean-scope>
</managed-bean>
4. Make a call on the page
<a:task mapId="Map0" value="#{MyTask}" rendered="true" taskInfo="#{MyTaskInfo}" />
Refer:
Code for space query and attribute text Query
Server Java lecture ----- extended tasks framework (1)
Server Java lecture ---- taskinfo of task framework Extension