Xpages 创建工具提示托管bean

Xpages 创建工具提示托管bean,xpages,managed-bean,Xpages,Managed Bean,这是我上一篇文章的后续文章,我已经编写了代码(未经测试),因此似乎无法正确调用托管Bean。我的配置包含以下内容: <managed-bean id="ToolTip"> <managed-bean-name>WFSToolTip</managed-bean-name> <managed-bean-class>ca.workflo.wfsToolTip.ToolTipText</managed-bean-class> <manag

这是我上一篇文章的后续文章,我已经编写了代码(未经测试),因此似乎无法正确调用托管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>
我的类位于构建路径中。我有一个简单的XPage,上面有一个字段和该字段的工具提示。工具提示的代码为:

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

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

执行JavaScript计算表达式时出错 脚本解释器错误,第1行,第12列:调用java类“ca.workflo.wfsToolTip.ToolTipText”上的方法“gettooltipext(string)”时出错

JavaScript代码

1:wfsooltip.gettooltipext(“更多内容”)

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

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


谢谢。

我从未见过那个id属性。。faces配置中的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>

我想你可以在没有可序列化的情况下离开。。。虽然我一直在实现,但我确信您需要无参数构造函数。

我从未见过id属性。。faces配置中的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>
我想你可以在没有可序列化的情况下离开。。。虽然我一直在实现,但我确信您需要无参数构造函数。

您需要: -实现Serializable,它归结为声明它并提供一个版本 -实现映射。。。多一点工作

然后使用表达式语言而不是SSJS。它看起来像
{wfsooltip[“更多东西”]}

这就是这样一个类的外观。您需要:

  • 调整视图名称以反映所需的名称
  • 视图需要是平面视图,第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;
                }
            }
        }

    }
}
package com.notessensei.xpages;
导入java.io.Serializable;
导入java.util.Collection;
导入java.util.HashMap;
导入java.util.Map;
导入java.util.Set;
导入java.util.Vector;
导入lotus.domino.Base;
导入lotus.domino.Database;
导入lotus.domino.NotesException;
导入lotus.domino.View;
导入lotus.domino.ViewEntry;
导入lotus.domino.ViewEntryCollection;
导入com.ibm.xsp.extlib.util.ExtLibUtil;
公共类参数实现可序列化的映射{
私有最终静态字符串CONFIG_VIEW=“keywords”;
私有静态最终长serialVersionUID=1L;
私有最终映射internalMap=新HashMap();
公共参数(){
此参数为.populateParameters(internalMap);
}
私有void populateParameters(映射地图){
数据库d=ExtLibUtil.getCurrentDatabase();
试一试{
视图v=d.getView(配置视图);
ViewEntryCollection向量=v.getAllEntries();
ViewEntry ve=vec.getFirstEntry();
ViewEntry nextVe=null;
while(ve!=null){
nextVe=vec.getNextEntry(ve);
//加载参数,第0列为键,第0列为值
Vector colVal=ve.getColumnValues();
put(colVal.get(0.toString(),colVal.get(1.toString());
//清理
这个。切碎(ve);
ve=nextVe;
}
//回收,但不是当前数据库!!!
这个。切碎(ve,nextVe,vec,v);
}捕获(注e){
e、 printStackTrace();
}
}
公共空间清除(){
this.internalMap.clear();
this.populateParameters(this.internalMap);
}
公共布尔containsKey(对象键){
返回此.internalMap.containsKey(键);
}
公共布尔包含值(对象值){
返回此.internalMap.containsValue(值);
}
公共集入口集(){
返回此.internalMap.entrySet();
}
公共字符串获取(对象键){
返回此.internalMap.get(键);
}
公共布尔值为空(){
返回此.internalMap.isEmpty();
}
公共集密钥集(){
返回此.internalMap.keySet();
}
公共字符串put(字符串键、字符串值){
返回此.internalMap.put(键,值);
}
public void putAll(地图您需要:
-实现Serializable,它归结为声明它并提供一个版本
-实施地图…多做一点工作

然后使用表达式语言而不是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;
                }
            }
        }

    }
}
package com.notessensei.xpages;
导入java.io.Serializable;
导入java.util.Collection;
导入java.util.HashMap;
导入java.util.Map;
导入java.util.Set;
导入java.util.Vector;
导入lotus.domino.Base;
导入lotus.domino.Database;
导入lotus.domino.NotesException;
导入lotus.domino.View;
导入lotus.domino.ViewEntry;
导入lotus.domino.ViewEntryCollection;
导入com.ibm.xsp.extlib.util.ExtLibUtil;
公共类参数实现可序列化的映射{
私有最终静态字符串CONFIG_VIEW=“keywords”;
私有静态最终长serialVersionUID=1L;
普里瓦
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?
                    }
                }
            }
        }
    }
}