Xpages 和 EL : Syntax for retrieving HashMap Values

标签 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.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/

相关文章:

java - 使用 openNTF Domino API 作为插件开发中的依赖项

javascript - 如何使 XPage 应用程序布局左栏可折叠/可调整大小?

css - Xpages 复选框将多列分组?

java - 无法在从代理调用的 java 中获取 openNTF session - 版本 10.0.1

jsp - 如何使用get方法通过URL将包含双引号的字符串从jsp传递到servlet

xpages - 去掉货币的小数部分

jakarta-ee - 如何使用 JSF 2.0 和 EL 2.2 为 Tomcat 7 配置 Maven pom?

java - 在jsp中的if条件中定义变量

java - Eclipse 报告 JSP 文件中的语法错误,但应用程序运行正常