【问题标题】:Creating a ToolTip Managed bean创建 ToolTip 托管 bean
【发布时间】:2014-08-23 21:54:58
【问题描述】:

这是我在ToolTip Performance in XPages 上的帖子的后续内容,我已经编写了代码(未经测试),因此我似乎无法正确调用我的托管 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>

我已经将我的代码精简到最低限度:

package ca.workflo.wfsToolTip;

public class ToolTipText   {

    public String getToolTipText(String key){
        return key;
    }
}

我的班级在构建路径中。我有一个简单的 XPage,上面有一个文件和该字段的工具提示。工具提示的代码是:

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

当我在浏览器中加载测试 XPage 时,出现以下错误:

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

JavaScript 代码

1: WFSToolTip.getToolTipText("More Stuff");

我不明白为什么调用 getToolTipText 会失败。

谁能看到我哪里出错了。这是我的第一个托管 Bean,目前它正在管理我,而不是相反。

谢谢。

【问题讨论】:

    标签: xpages managed-bean


    【解决方案1】:

    我从未见过那个 id 属性。我在 faces-config 中的 bean 看起来像这样:

    <managed-bean>
        <managed-bean-name>CurrentJob</managed-bean-name>
        <managed-bean-class>com.domain.inventory.Job</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    

    技术管理的 bean 应该实现 Serializable 并有一个空白的构造函数。所以你应该在里面有这样的东西:

    public ToolTipText() {
    
    }
    

    我认为你可以在没有 Serializable 的情况下逃脱...虽然我总是实现但我确定你需要无参数构造函数。

    【讨论】:

    • David - 我从 debuToolBar 的配置中获得了 并将其包含在我的中。 Stephan Whissel 发布的代码确实很有帮助,我的代码几乎可以正常工作了。如果它按我想要的方式工作,它应该真正加快 ExtLib ToolTip。我不得不将 ToolTips 从一个非常大的 XPage 中移除,该 XPage 确实需要 ToolTip 的上下文相关帮助,但它非常缓慢。我发现每个工具提示都在一个会话中多次查找帮助数据库。这将制作一个很棒的 NotesIn9 视频。
    【解决方案2】:

    您需要: - 实现 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;
                    }
                }
            }
    
        }
    }
    

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

    【讨论】:

    • EL 不会尝试为“更多东西”调用吸气剂吗?我仍然使用 SSJS 进行方法调用,所以 #{WFSToolTip.getToolTipText("More Stuff");}。我发现的唯一警告是我认为您正在创建一个 JavaScript 对象的实例 - 因此是一个 JavaScript 字符串 - 需要将其转换为 Java 对象 - 一个 Java 字符串。通常这没问题,但某些数据类型可能会让您感到困惑,例如数字。
    • 当你的 Java 对象实现 Map 接口时,WFSToolTip["More Stuff"] 会调用 Map.get("More Stuff") 方法。
    • 啊,是的,当然。这就是实现 Map 和 Serializable 的原因。
    • 嗯哇。我不完全明白,但我认为整个“实现地图”和 EL 分支是一个非常有趣的概念。除了可能在蒂姆的一个 NotesIn9 视频中,我以前从未见过这样做......
    • 它会招来各种鬼鬼祟祟的东西。想象一下地图返回的不是字符串,而是地图,你可以做一些有趣的事情,比如 Invoice["12342"]["Total"]
    【解决方案3】:

    感谢所有回复并提供帮助的人,尤其是 Stephan Wissel。我想我会发布我的斯蒂芬代码版本,几乎相同。将类设为 ApplicationScope 存在问题,因为您需要关闭 HTTP 任务以刷新和重新加载该类。我所做的是在自定义控件中添加了一个按钮,在该控件中我可以查看工具提示视图,我在其中执行 CRUD 内容,并在按钮中执行 WFSToolTip().clear() 并重建地图。很简约。我的下一个任务是尝试使用 JAVA 进行 CRUD 并直接更新地图。目前虽然我需要继续我的下一个任务。 我的下一个任务围绕着一个非常相似的类。我有一个包含所有基本设计和代码的主数据库。然后我有一个或多个应用程序使用该代码并将文档存储在他们自己的数据库中,其中包含该特定应用程序的表单和视图。在master中我创建了一个或多个应用程序文档。这些文档中的每一个都包含 AppName(键值),然后 Map 值是一个数组(向量),其中包含应用程序数据库的 ReplicaID 和一些其他信息。我的类为每个应用程序加载一个地图条目,并从几个地方收集有关应用程序的一堆其他信息并将其存储在地图值中。此时我可以设置 Database db = thisClass.getDatabase("App Name")。因此单个自定义控件可用于任何/所有应用程序。很酷。我想我可以喜欢这个。 无论如何,这里是我用于工具提示的代码 - 顺便说一句,它采用了一个包含大约 175 个字段和 100 多个工具提示的 XPage,从缓慢到可以接受。关于它的好处是 XPage 正在创建一个流程配置文件文档,并且一旦创建它就不会经常作为管理员操作进行修改 - 而不是日常用户操作。 请随时指出代码的错误、遗漏或建议:

    package ca.workflo.wfsToolTip;
    
    import lotus.domino.Base;
    import lotus.domino.Session;
    import lotus.domino.Database;
    import lotus.domino.View;
    import lotus.domino.NotesException;
    import lotus.domino.ViewEntry;
    import lotus.domino.ViewEntryCollection;
    
    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 com.ibm.xsp.extlib.util.ExtLibUtil;
    
    public class ToolTipText implements Serializable, Map<String, String> {
    
        private static final long serialVersionUID = 1L;
        private Session s;
        private String repID;
        private Database db;
        private Database helpDB;
        private View helpView;
        private ViewEntry ve;
        private ViewEntry tVE;
        private ViewEntryCollection veCol;
        private final Map<String, String> internalMap = new HashMap<String, String>();
    
        public ToolTipText() {
            this.populateMap(internalMap);
        }
    
        private void populateMap(Map<String, String> theMap) {
    
            try {
                s = ExtLibUtil.getCurrentSession();
                db = s.getCurrentDatabase();
                repID = db.getProfileDocument("frmConfigProfile", "").getItemValue(
                        "WFSHelpRepID").firstElement().toString();
                helpDB = s.getDbDirectory(null).openDatabaseByReplicaID(repID);
                helpView = helpDB.getView("vwWFSToolTipHelp");
                veCol = helpView.getAllEntries();
                ve = veCol.getFirstEntry();
                ViewEntry tVE = null;
                while (ve != null) {
                    tVE = veCol.getNextEntry(ve);
                    Vector colVal = ve.getColumnValues();
                    theMap.put(colVal.get(0).toString(), colVal.get(1).toString());
                    recycleObjects(ve);
                    ve = tVE;
                }
            } catch (NotesException e) {
                System.out.println(e.toString());
            }finally{
                recycleObjects(ve, tVE, veCol, helpView, helpDB);
            }
        }
    
        public void clear() {
            this.internalMap.clear();
            this.populateMap(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) {
            try {
                if (this.internalMap.containsKey(key)) {
                    return this.internalMap.get(key);
                } else {
                    return "There is no Tooltip Help for " + key;
                }
    
            } catch (Exception e) {
                return "error in tooltip get Object ";
            }
        }
    
        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();
        }
    
        public static void recycleObjects(Object... args) {
            for (Object o : args) {
                if (o != null) {
                    if (o instanceof Base) {
                        try {
                            ((Base) o).recycle();
                        } catch (Throwable t) {
                            // who cares?
                        }
                    }
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-23
      • 2016-07-08
      • 2012-02-24
      • 2012-07-06
      相关资源
      最近更新 更多