创建一个ToolTip托管bean [英] Creating a ToolTip Managed bean

查看:65
本文介绍了创建一个ToolTip托管bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我以前的文章 XPages中的工具提示性能的后续操作代码来编写它(未经测试),所以我似乎无法正确调用我的Managed Bean.我的配置包含以下内容:

This is a followup to my previous post at ToolTip Performance in XPages I have got the code to do it written (not tested) so I can't seem to get my Managed Bean to get called properly. My config contians the following:

<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>

并且我已将代码精简到最低限度:

and I have stripped my code down to the bare minimum:

package ca.workflo.wfsToolTip;

public class ToolTipText   {

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

我的课程在构建路径中.我有一个简单的XPage,上面有一个文件,以及该字段的工具提示.工具提示的代码是:

My class is in the build path. I have a simple XPage with one filed on it and a tool tip for that field. The code for the tooltip is:

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

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

When I load the test XPage in the browser I get an error that:

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

Error while executing JavaScript computed expression Script interpreter error, line=1, col=12: Error calling method 'getToolTipText(string)' on java class 'ca.workflo.wfsToolTip.ToolTipText'

JavaScript代码

JavaScript code

1:WFSToolTip.getToolTipText(更多内容");

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

我不知道为什么对getToolTipText的调用会失败.

I can't figure out why the call to getToolTipText would fail.

谁能看到我要去的地方.这是我的第一个Managed Bean,目前正在管理我,而不是相反.

Can anyone see where I'm going wrong. This is my first Managed Bean and at the moment it is managing me rather than the other way around.

谢谢.

推荐答案

您需要: -实现Serializable,归纳起来可以说明它并提供一个版本 -实施Map ...还要做更多的工作

You need to: - implement Serializable which boils down to state it and provide a version - implement Map ... a little more work

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

Then you use Expression Language instead of SSJS. It would look like #{WFSToolTip["More Stuff"]}

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

This is how such a class would look like. You need to:

  • 调整视图名称以反映您想要的名称
  • 视图必须是平坦的,第1列=工具提示名称,第2列=工具提示文本
  • 更新配置中的值后,需要在某个地方(在管理/配置页面上)调用WFSToolTip.clear();(在SSJS中).
  • adjust the view name to reflect the name you want
  • the view needs to be flat, column 1 = tooltip name, column 2 = tooltip text
  • somewhere (on an admin/config page) you need to call WFSToolTip.clear(); (in SSJS) after you update the values in the configuration.

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

The example doesn't lazyload since running though a view navigator once is really fast. No point to do all these lookups.

您在这里:

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的区别仅在于填充它的构造函数.希望能澄清这一点.

The difference to a regular HashMap is only the constructor that populates it. Hope that clarifies it.

这篇关于创建一个ToolTip托管bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆