在我的 Xpages 應(yīng)用程序中,我有一個(gè) java 類(lèi),我想在其中將 Document 設(shè)置為全局屬性并在我的方法中重用。該文檔代表一個(gè) Notes 配置文檔,我只想執(zhí)行一次查找。不幸的是,它沒(méi)有按預(yù)期工作。也許有人可以指導(dǎo)我正確的過(guò)程?首先,我設(shè)置了一個(gè)托管 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>我的課程包含幾種將轉(zhuǎn)到不同系統(tǒng)的方法。系統(tǒng)的所有 URL 都存儲(chǔ)在 Notes 配置文檔中,我只想加載一次并在這些方法中重復(fù)使用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 發(fā)起的:emplDataMining.getConfiguration(); emplDataMining.collectDataFromSystemX(//passing in the variables which are setup in getConfiguration method)所以我主要擔(dān)心的是配置文件 Document 沒(méi)有正確設(shè)置或在方法之間交換。有人能告訴我我忽略了什么嗎?
1 回答

天涯盡頭無(wú)女友
TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊
有2個(gè)問(wèn)題:
在視圖范圍內(nèi),您打開(kāi)的每個(gè)文檔都會(huì)重新加載 bean。如果它是一個(gè)配置文件,你想使用會(huì)話(huà)范圍
您不能在托管 bean 中存儲(chǔ) Notes 對(duì)象(請(qǐng)求范圍可能有效)。你做什么:在你的 bean 的構(gòu)造函數(shù)中,加載文檔并將字段值提取到 bean 內(nèi)部變量(字符串、列表等)中。那會(huì)給你你想要的
添加回答
舉報(bào)
0/150
提交
取消