參考:Server Java 開發實戰---自訂command
command裡面就是命令按鈕。在我們的ArcGIS Server的Web ADF裡面,command被用來做一些不用跟地圖互動的工作.1.編寫java類,實現command的功能
command裡面就是命令按鈕。在我們的ArcGIS Server的Web ADF裡面,command被用來做一些不用跟地圖互動的工作.
1.編寫java類,實現command的功能
代碼
package com.demo;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.geometry.WebExtent;
public class MyFullExtent {
WebContext context;
public WebContext getContext() {
return context;
}
public void setContext(WebContext context) {
this.context = context;
}
public void setFullExtent() {
try {
WebExtent ex = context.getWebMap().getFullExtent();
context.getWebMap().setCurrentExtent(ex);
context.refresh();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
2.在faces-config.xml檔案,在裡面添加如下配置:web context作為一個屬性,用來初始化MyFullExtent,#{mapContext}指向了一個在faces-config.xml檔案中定義的另外一個Bean
代碼
<managed-bean>
<managed-bean-name>myFullExtent</managed-bean-name>
<managed-bean-class>com.demo. MyFullExtent </managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>context</property-name>
<value>#{mapContext}</value>
</managed-property>
</managed-bean>
3.在頁面中調用
<a:command id="fullExtent"
action="#{myFullExtent. setFullExtent }"
toolText="全圖顯示" />
4.錯誤:Managedbean myFullExtent could not be created 引用的對象 "#{mapContext}" 的範圍比引用對象小原因為myFullExtent的managed-bean-scope屬性為session,而mapContext的managed-bean-scope屬性為request,調用的對象的作用範圍應大於等於調用者的作用範圍。此處將session改為request即可。