首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在java类中将文档设置为全局属性,不起作用

在java类中将文档设置为全局属性,不起作用
EN

Stack Overflow用户
提问于 2018-10-22 03:05:29
回答 1查看 65关注 0票数 2

在我的Xpages应用程序中,我有一个java类,我想在其中将文档设置为全局属性并在我的方法中重用。该文档表示一个Notes配置文档,我只想执行一次查找。不幸的是,它并没有像预期的那样工作。也许有人能引导我走正确的流程?

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

代码语言:javascript
复制
<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配置文档中,我只想加载一次该文档,并在这些方法中重用它

代码语言:javascript
复制
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启动的:

代码语言:javascript
复制
emplDataMining.getConfiguration(); 
emplDataMining.collectDataFromSystemX(//passing in the variables which are setup in getConfiguration method)

因此,我主要关心的是配置文件文档没有正确设置或在方法之间进行交换。

谁能告诉我我漏掉了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-22 07:26:11

有两个问题:

每打开一个文档,

  • 都会被重新加载。如果它是一个配置文档,您想要使用会话作用域Notes,那么就不能将

对象存储在托管bean中(请求作用域可能可以)。替代方法:在bean的构造函数中,加载文档并将字段值提取到bean内部变量(字符串、列表等)中。这将会给你你想要的

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52918861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档