创建ToolTip托管bean

Bil*_*l F 1 managed-bean xpages

这是我在XPage中的ToolTip性能的上一篇文章的后续内容我已经编写了代码(未经过测试),所以我似乎无法让我的Managed Bean被正确调用.我的配置包含以下内容:

<managed-bean id="ToolTip">
<managed-bean-name>WFSToolTip</managed-bean-name>
<managed-bean-class>ca.workflo.wfsToolTip.ToolTipText</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Run Code Online (Sandbox Code Playgroud)

我已经将我的代码剥离到最低限度:

package ca.workflo.wfsToolTip;

public class ToolTipText   {

    public String getToolTipText(String key){
        return key;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的班级在构建路径中.我有一个简单的XPage,其中有一个提交,并为该字段的工具提示.工具提示的代码是:

<xe:tooltip id="tooltip1" for="inputText1">
<xe:this.label>
<![CDATA[#{javascript:WFSToolTip.getToolTipText("More Stuff");}]]>
</xe:this.label>
</xe:tooltip>
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中加载测试XPage时,我得到一个错误:

执行JavaScript计算表达式时出错脚本解释器错误,line = 1,col = 12:在java类'ca.workflo.wfsToolTip.ToolTipText'上调用方法'getToolTipText(string)'时出错

JavaScript代码

1:WFSToolTip.getToolTipText("更多东西");

我无法弄清楚为什么调用getToolTipText会失败.

任何人都可以看到我出错的地方.这是我的第一个Managed Bean,目前它正在管理我而不是相反.

谢谢.

stw*_*sel 5

你需要: - 实现Serializable,归结为陈述它并提供一个版本 - 实现Map ...多一点工作

然后使用表达式语言而不是SSJS.它看起来像#{WFSToolTip["More Stuff"]}

这就是这样一个类的样子.你需要:

  • 调整视图名称以反映所需的名称
  • 视图需要是平的,第1列=工具提示名称,第2列=工具提示文本
  • 某个地方(在管理员/配置页面上)您需要WFSToolTip.clear();在更新配置中的值后调用(在SSJS中).

该示例不会延迟加载,因为运行一次视图导航器非常快.没有必要做所有这些查找.

干得好:

package com.notessensei.xpages;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import lotus.domino.Base;
import lotus.domino.Database;
import lotus.domino.NotesException;
import lotus.domino.View;
import lotus.domino.ViewEntry;
import lotus.domino.ViewEntryCollection;

import com.ibm.xsp.extlib.util.ExtLibUtil;

public class Parameters implements Serializable, Map<String, String> {

    private final static String       CONFIG_VIEW      = "keywords";

    private static final long         serialVersionUID  = 1L;
    private final Map<String, String>   internalMap    = new HashMap<String, String>();

    public Parameters() {
        this.populateParameters(internalMap);
    }

    private void populateParameters(Map<String, String> theMap) {

        Database d = ExtLibUtil.getCurrentDatabase();
        try {
            View v = d.getView(CONFIG_VIEW);
            ViewEntryCollection vec = v.getAllEntries();
            ViewEntry ve = vec.getFirstEntry();
            ViewEntry nextVe = null;

            while (ve != null) {
                nextVe = vec.getNextEntry(ve);
                // Load the parameters, column 0 is the key, column 0 the value
                Vector colVal = ve.getColumnValues();
                theMap.put(colVal.get(0).toString(), colVal.get(1).toString());
                // Cleanup
                this.shred(ve);
                ve = nextVe;
            }
            // recycle, but not the current database!!!
            this.shred(ve, nextVe, vec, v); 
        } catch (NotesException e) {
            e.printStackTrace();
        }
    }

    public void clear() {
        this.internalMap.clear();
        this.populateParameters(this.internalMap);
    }

    public boolean containsKey(Object key) {
        return this.internalMap.containsKey(key);
    }

    public boolean containsValue(Object value) {
        return this.internalMap.containsValue(value);
    }

    public Set<java.util.Map.Entry<String, String>> entrySet() {
        return this.internalMap.entrySet();
    }

    public String get(Object key) {
        return this.internalMap.get(key);
    }

    public boolean isEmpty() {
        return this.internalMap.isEmpty();
    }

    public Set<String> keySet() {
        return this.internalMap.keySet();
    }

    public String put(String key, String value) {
        return this.internalMap.put(key, value);
    }

    public void putAll(Map<? extends String, ? extends String> m) {
        this.internalMap.putAll(m);
    }

    public String remove(Object key) {
        return this.internalMap.remove(key);
    }

    public int size() {
        return this.internalMap.size();
    }

    public Collection<String> values() {
        return this.internalMap.values();
    }

    private void shred(Base... morituri) {

        for (Base obsoleteObject : morituri) {
            if (obsoleteObject != null) {
                try {
                    obsoleteObject.recycle();
                } catch (NotesException e) {
                    // We don't care we want go get
                    // rid of it anyway
                } finally {
                    obsoleteObject = null;
                }
            }
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

与常规HashMap的区别仅在于填充它的构造函数.希望澄清一下.