gpt4 book ai didi

Xpages 和 EL : Syntax for retrieving HashMap Values

转载 作者:行者123 更新时间:2023-12-02 11:55:03 24 4
gpt4 key购买 nike

我有一个用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.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;
}
}

获取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;
}

此外,#{PCConfig.status[0]} 尝试读取键 0 的值。但你的 HashMap 状态中没有键 0...

关于Xpages 和 EL : Syntax for retrieving HashMap Values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36720769/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com