问题描述
我想在 Notes 视图中设置一个管理 Notes 文档的托管 bean,我将应用程序首选项存储在其中(例如,服务器上存储附件的路径、应用程序标题、要显示的徽标等)有没有人有这样一个 bean 的例子以及我应该如何使用它?
I would like to set up a managed bean that manages a Notes document in Notes view where I store application preferences in (e.g. path on server to store attachments, application title, which logo to display etc)Has anyone an example for such a bean and how I should use it?
当前我加载了一个 SSJS 库,并将所有内容放在应用程序范围或会话范围变量中.
Current I load a SSJS library an place everything in application scope or session scope variables.
推荐答案
以下是此类托管 bean 的一个简单示例.
Here is a simple example for such a managed bean.
首先创建一个Java类.我称之为配置".它读取视图Config"中的第一个文档,并在实例化时(=第一次调用)将项目放入 java 字段中.这样做,您可以在读取所有项目后回收多米诺骨牌对象,然后将值保存在内存中.
First create a Java class. I called it "Config". It reads the first document in view "Config" and puts at instantiation time (=first call) the items in java fields. Doing this you can recycle the domino objects after reading all items and have the values in memory then.
package de.leonso;
import java.io.Serializable;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.View;
import com.ibm.xsp.extlib.util.ExtLibUtil;
public class Config implements Serializable {
private static final long serialVersionUID = 1L;
private String applicationTitle;
// ... other private fields
public Config() throws NotesException {
Database db = ExtLibUtil.getCurrentSession().getCurrentDatabase();
View view = db.getView("Config");
Document doc = view.getFirstDocument();
applicationTitle = doc.getItemValueString("ApplicationTitle");
// ... read all other items and store them in private fields
doc.recycle();
view.recycle();
db.recycle();
}
public String getApplicationTitle() {
return applicationTitle;
}
// ... getters for other private fields
}
接下来在 faces-config.xml 文件中将此 Java 类定义为托管 bean:
Next define this Java class as a managed bean in faces-config.xml file:
<faces-config>
<managed-bean>
<managed-bean-name>config</managed-bean-name>
<managed-bean-class>de.leonso.Config</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
</faces-config>
您可以将应用程序"(每个服务器的实例)或会话"(每个用户的实例)用作范围.
You can use as scope "application" (instance per server) or "session" (instance per user).
然后你可以在 JavaScript 中使用配置 bean:
Then you can use the config bean in JavaScript:
#{javascript:var titel = config.applicationTitle; ...}
或表达语言:
#{config.applicationTitle}
这应该为您开发高级版本的配置 bean 提供了一个很好的起点.
That should give you a good starting point to develop an advanced version of a config bean.
这篇关于如何设置托管 bean 以使用 Notes 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!