java - 将 Document 设置为 java 类中的全局属性,不起作用

标签 java xpages xpages-ssjs

在我的 Xpages 应用程序中,我有一个 java 类,我想在其中将 Document 设置为全局属性并在我的方法中重复使用。该文档代表一个 Notes 配置文档,我只想执行一次查找。不幸的是它没有按预期工作。也许有人可以指导我采取正确的流程?

首先我设置了一个托管 bean:

<managed-bean>
    <managed-bean-name>emplDataMining</managed-bean-name>
    <managed-bean-class>se.bank.employeeApp.utils.EmployeeDataMining</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
</managed-bean>

我的类包含几种将进入不同系统的方法。系统的所有 URL 都存储在 Notes 配置文档中,我只想加载一次并在这些方法中重复使用

public class EmployeeDataMining implements Serializable{

    private static final long serialVersionUID = 1L;
    private Document configuration;

    //constructor class. not so very special, so I wont post it

    public void getConfiguration(){
        //setting up database and view
        //only 1 document stored in the view so I can hard-code the reference
        configuration = vw.getDocumentByKey("ConfigDocument", true);
        //... rest of code e.g. setting up httpclient, JSONobj
    }

    public void collectDataFromSystemX(CloseableHttpClient httpclient, Employee employee, JSONObject JSONobj){
        //I wont post all of my code  
        HttpPost httpPost = new HttpPost(this.configuration.getItemValueString("urlSystemX"));
        //this.configuration is null :-?
        //..rest of code
    }

    public void collectDataFromSystemY(CloseableHttpClient httpclient, Employee employee, JSONObject JSONobj){
        //I wont post all of my code  
        HttpPost httpPost = new HttpPost(this.configuration.getItemValueString("urlSystemY"));
        //this.configuration is null :-?
        //..rest of code
    }

}

我的代码是从SSJS发起的:

emplDataMining.getConfiguration(); 
emplDataMining.collectDataFromSystemX(//passing in the variables which are setup in getConfiguration method)

所以我主要担心的是配置文件 Document 没有在方法之间正确设置或交换。

有人可以告诉我我忽略了什么吗?

最佳答案

有 2 个问题:

  • 作为 View 范围,bean 会为您打开的每个文档重新加载。如果它是一个配置文档,您想使用 session 范围
  • 您无法将 Notes 对象存储在托管 bean 中(请求范围可能有效)。您应该做什么:在 bean 的构造函数中,加载文档并将字段值提取到 bean 内部变量(字符串、列表等)中。这会给你你想要的

关于java - 将 Document 设置为 java 类中的全局属性,不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52918861/

相关文章:

java - Android:椭圆形看起来很糟糕

javascript - 如何放置 xpages 正则表达式(第一个字符和最后一个字符)不能是特殊字符

java - 如何使用 "xagent"创建多个导出?

lotus-notes - 在代理中运行服务器端 javascript

java - 如何在同一个窗口中依次打开2个类(class)

java - Spark : Named_struct requires at least one argument

java - 制服中的平移/旋转/缩放和矩阵

java - 支持包 "com.ibm.misc"及其类

javascript - XPage 如何在 xp :this. 脚本中单击时获取链接的 id?

xpages - 在 Notes 和 Web 浏览器中预览时的图像 URL