Xpages和EL:检索HashMap值的语法
我有一个用Java编写的cacheBean。我使用EL成功地提取了向量,但是我有一个HashMap,当我试图访问一个值时,我抛出了一个错误 我的cacheBean是:Xpages和EL:检索HashMap值的语法,xpages,el,Xpages,El,我有一个用Java编写的cacheBean。我使用EL成功地提取了向量,但是我有一个HashMap,当我试图访问一个值时,我抛出了一个错误 我的cacheBean是: package com.scoular.cache; import java.io.Serializable; import java.util.HashMap; import java.util.Vector; import org.openntf.domino.utils.Factory; import org.openn
package com.scoular.cache;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Vector;
import org.openntf.domino.utils.Factory;
import org.openntf.domino.Database;
import org.openntf.domino.Session;
import org.openntf.domino.View;
import org.openntf.domino.ViewEntry;
import org.openntf.domino.ViewNavigator;
public class PCConfig implements Serializable {
private static final long serialVersionUID = 1L;
private Database thisDB;
private Database compDirDB;
public Database PCDataDB;
public HashMap<Integer, String> status = new HashMap<Integer, String>();
public static Vector<Object> geoLocations = new Vector<Object>();
public static Vector<Object> models = new Vector<Object>();
// @SuppressWarnings("unchecked")
private void initConfigData() {
try {
getStatus();
getGeoLocations();
getModels();
} catch (Exception e) {
e.printStackTrace();
}
}
public PCConfig() {
// initialize application config
System.out.println("Starting CacheBean");
initConfigData();
System.out.println("Ending CacheBean");
}
public static void setModels(Vector<Object> models) {
PCConfig.models = models;
}
public void getStatus() {
status.put(1, "In Inventory");
status.put(2, "Being Built");
status.put(3, "In Production");
status.put(4, "Aquiring PC");
status.put(5, "Decommissioning");
}
public Vector<Object> getGeoLocations() {
if (PCConfig.geoLocations == null || PCConfig.geoLocations.isEmpty()) {
try {
Session session = Factory.getSession();
thisDB = session.getCurrentDatabase();
compDirDB = session.getDatabase(thisDB.getServer(), "compdir.nsf", false);
View geoView = compDirDB.getView("xpGeoLocationsByName");
for (ViewEntry ce : geoView.getAllEntries()) {
Vector<Object> rowVal = ce.getColumnValues();
geoLocations.addElement(rowVal.elementAt(0));
}
} catch (Exception e) {
e.printStackTrace();
}
}
return geoLocations;
}
public Vector<Object> getModels() {
if (PCConfig.models == null || PCConfig.models.isEmpty()) {
try {
Session session = Factory.getSession();
thisDB = session.getCurrentDatabase();
PCDataDB = session.getDatabase(thisDB.getServer(), "scoApps\\PC\\PCData.nsf", false);
ViewNavigator vn = PCDataDB.getView("dbLookupModels").createViewNav();
ViewEntry entry = vn.getFirstDocument();
while (entry != null) {
Vector<Object> thisCat = entry.getColumnValues();
if (entry.isCategory()) {
String thisCatString = thisCat.elementAt(0).toString();
models.addElement(thisCatString);
}
entry = vn.getNext(entry);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return models;
}
}
package com.scoular.cache;
导入java.io.Serializable;
导入java.util.HashMap;
导入java.util.Vector;
导入org.openntf.domino.utils.Factory;
导入org.openntf.domino.Database;
导入org.openntf.domino.Session;
导入org.openntf.domino.View;
导入org.openntf.domino.ViewEntry;
导入org.openntf.domino.ViewNavigator;
公共类PCConfig实现可序列化{
私有静态最终长serialVersionUID=1L;
私有数据库;
私有数据库compDirDB;
公共数据库PCDataDB;
public HashMap status=new HashMap();
公共静态矢量地理位置=新矢量();
公共静态向量模型=新向量();
//@SuppressWarnings(“未选中”)
私有void initConfigData(){
试一试{
getStatus();
getGeoLocations();
getModels();
}捕获(例外e){
e、 printStackTrace();
}
}
公共PCConfig(){
//初始化应用程序配置
System.out.println(“启动CacheBean”);
initConfigData();
System.out.println(“结束缓存bean”);
}
公共静态模型(向量模型){
PCConfig.models=模型;
}
public void getStatus(){
状态。投入(1,“库存中”);
状态。put(2,“正在建造”);
状态。投入(3,“投入生产”);
状态。put(4,“获取PC”);
状态。put(5,“退役”);
}
公共向量getGeoLocations(){
if(PCConfig.geoplocations==null | | PCConfig.geoplocations.isEmpty()){
试一试{
Session Session=Factory.getSession();
thisDB=session.getCurrentDatabase();
compDirDB=session.getDatabase(thisDB.getServer(),“compdir.nsf”,false);
View geoView=compDirDB.getView(“xpGeoLocationsByName”);
对于(ViewEntry ce:geoView.getAllEntries()){
Vector rowVal=ce.getColumnValues();
地理位置.附录(rowVal.elementAt(0));
}
}捕获(例外e){
e、 printStackTrace();
}
}
返回地理位置;
}
公共向量getModels(){
if(PCConfig.models==null | | PCConfig.models.isEmpty()){
试一试{
Session Session=Factory.getSession();
thisDB=session.getCurrentDatabase();
PCDataDB=session.getDatabase(thisDB.getServer(),“scoApps\\PC\\PCData.nsf”,false);
ViewNavigator vn=PCDataDB.getView(“dbLookupModels”).createViewNav();
ViewEntry=vn.getFirstDocument();
while(条目!=null){
向量thisCat=entry.getColumnValues();
if(entry.isCategory()){
字符串thisCatString=thisCat.elementAt(0.toString();
模型.附加元素(thisCatString);
}
entry=vn.getNext(entry);
}
}捕获(例外e){
e、 printStackTrace();
}
}
收益模型;
}
}
获取a值的代码是:
<xp:text escape="true" id="computedField2">
<xp:this.value><![CDATA[#{PCConfig.status[0]}]]></xp:this.value></xp:text>
您的方法
getStatus()
必须返回HashMap
public HashMap<Integer, String> getStatus() {
...
return status;
}
public HashMap getStatus(){
...
返回状态;
}
此外,
{PCConfig.status[0]}
尝试读取键0
的值。您的HashMap状态中没有键0
,但是…据我所知,您应该执行以下操作
#{javascript:PCConfig.status.get(1)}
谢谢,这很有效。我将computed字段的值更改为#{PCConfig.status[1]},但没有显示任何内容。如果我做一个#{PCConfig.status},那么我会得到所有的值,{1=在库存中,2=正在构建,3=在生产中,4=获取PC,5=停用}。EL似乎不适用于HashMap。改用HashMap。