jsf - XPages: How to acces an application scope bean from a session scope bean -
i need value application scope managed bean in session scope managed bean. not sure how done. saw poste here: https://guedebyte.wordpress.com/2012/05/19/accessing-beans-from-java-code-in-xpages-learned-by-reading-the-sourcecode-of-the-extensionlibrary/ bunch of errors... found this: jsf 2.0 accessing application scope bean bean im thinking maybe need redefine application bean??? totally clueless...
how can make happen?
here application scope bean's code:
public class appconfig implements serializable { private static final long serialversionuid = 2768250939591274442l; public appconfig() { initdefaults(); initfromconfigdoc(); } // control number of entries displayed in widgets private int nbwidgetfavorites = 0; private int nbwidgetmostpopular = 0; private int nbwidgettoolbox = 0; // control number of entries display in what's new view private int nbwhatsnew = 0; private string showdetailswhatsnew = "no"; //controls various search options private int nbsearchresults = 0; private int nbmaxsearchresults = 0; //the home page use each language private string homepageunid_fr = ""; private string homepageunid_en = ""; //application email address use (webmaster) // dev address private string appemailaddress = "devteamtest/dev@developmentcorp"; // uat address // prod address //path stats db private string statsdb = ""; //application message, if needed private string systemmessagefr = ""; private string systemmessageen = ""; //default lang (defined here session bean read app bean first // see if there's value stored there) private string defaultlang = ""; //default prov private string defaultprov = ""; // show province drop down? private string showprov = "no"; //various text "share link" emails private string senderemail = ""; private string sendername = ""; private string appurl = ""; private string emailtext = ""; private string clicklinktext = ""; private string emailfooter = ""; private string messageintro = ""; private string allowratingmodification = ""; /*****************************************************************************/ private void initdefaults() { // control number of entries displayed in widgets nbwidgetfavorites = 10; nbwidgetmostpopular = 10; nbwidgettoolbox = 10; nbwhatsnew = 15; showdetailswhatsnew = "no"; nbsearchresults = 25; nbmaxsearchresults = 100; homepageunid_fr = ""; homepageunid_en = ""; appemailaddress = "devteamtest/dev@developmentcorp"; statsdb = "belair\\xbibliostats.nsf"; systemmessagefr = ""; systemmessageen = ""; defaultlang = "fr"; defaultprov = "qc"; showprov = "no"; allowratingmodification = "1"; } /*****************************************************************************/ public boolean persisttoconfigdoc() { //write content of sessionscope vars config doc try { database db = extlibutil.getcurrentsession().getcurrentdatabase(); view view = db.getview("appconfig"); document doc = view.getfirstdocument(); if(doc == null) { doc = db.createdocument(); doc.replaceitemvalue("form", "appconfig"); } doc.replaceitemvalue("nbwidgetfavorites", this.nbwidgetfavorites); doc.replaceitemvalue("nbwidgetmostpopular", this.nbwidgetmostpopular); doc.replaceitemvalue("nbwidgettoolbox", this.nbwidgettoolbox); doc.replaceitemvalue("nbwidgettoolbox", this.nbwidgettoolbox); doc.replaceitemvalue("nbwhatsnew", this.nbwhatsnew); doc.replaceitemvalue("showdetailswhatsnew", this.showdetailswhatsnew); doc.replaceitemvalue("nbsearchresults", this.nbsearchresults); doc.replaceitemvalue("nbmaxsearchresults", this.nbmaxsearchresults); doc.replaceitemvalue("homepageunid_fr", this.homepageunid_fr); doc.replaceitemvalue("homepageunid_en", this.homepageunid_en); doc.replaceitemvalue("appemailaddress", this.appemailaddress); doc.replaceitemvalue("statsdb", this.statsdb); doc.replaceitemvalue("systemmessagefr", this.systemmessagefr); doc.replaceitemvalue("systemmessageen", this.systemmessageen); doc.replaceitemvalue("defaultlang", this.defaultlang); doc.replaceitemvalue("defaultprov", this.defaultprov); doc.replaceitemvalue("showprov", this.showprov); doc.replaceitemvalue("senderemail", this.senderemail); doc.replaceitemvalue("sendername", this.sendername); doc.replaceitemvalue("appurl", this.appurl); doc.replaceitemvalue("emailtext", this.emailtext); doc.replaceitemvalue("clicklinktext", this.clicklinktext); doc.replaceitemvalue("emailfooter", this.emailfooter); doc.replaceitemvalue("messageintro", this.messageintro); doc.replaceitemvalue("allowratingmodification", this.allowratingmodification); doc.save(); return true; } catch (notesexception e) { // todo auto-generated catch block e.printstacktrace(); return false; } } /*****************************************************************************/ public void initfromconfigdoc() { try { database db = extlibutil.getcurrentsession().getcurrentdatabase(); view view = db.getview("appconfig"); document doc = view.getfirstdocument(); if(doc != null) { //load default values if(doc.hasitem("nbwidgetfavorites")) { int tmp = doc.getitemvalueinteger("nbwidgetfavorites"); if(tmp > 0) { this.nbwidgetfavorites = tmp; } } if(doc.hasitem("nbwidgetmostpopular")) { int tmp = doc.getitemvalueinteger("nbwidgetmostpopular"); if(tmp > 0) { this.nbwidgetmostpopular = tmp; } } if(doc.hasitem("nbwidgettoolbox")) { int tmp = doc.getitemvalueinteger("nbwidgettoolbox"); if(tmp > 0) { this.nbwidgettoolbox = tmp; } } if(doc.hasitem("nbwhatsnew")) { int tmp = doc.getitemvalueinteger("nbwhatsnew"); if(tmp > 0) { this.nbwhatsnew = tmp; } } if(doc.hasitem("showdetailswhatsnew")) { string tmp = doc.getitemvaluestring("showdetailswhatsnew"); this.showdetailswhatsnew = tmp; } if(doc.hasitem("nbsearchresults")) { int tmp = doc.getitemvalueinteger("nbsearchresults"); if(tmp > 0) { this.nbsearchresults = tmp; } } if(doc.hasitem("nbmaxsearchresults")) { int tmp = doc.getitemvalueinteger("nbmaxsearchresults"); if(tmp > 0) { this.nbmaxsearchresults = tmp; } } if(doc.hasitem("homepageunid_fr")) { string tmp = doc.getitemvaluestring("homepageunid_fr"); if(!"".equals(tmp)) { this.homepageunid_fr = tmp; } } if(doc.hasitem("homepageunid_en")) { string tmp = doc.getitemvaluestring("homepageunid_en"); if(!"".equals(tmp)) { this.homepageunid_en = tmp; } } if(doc.hasitem("appemailaddress")) { string tmp = doc.getitemvaluestring("appemailaddress"); if(!"".equals(tmp)) { this.appemailaddress = tmp; } } if(doc.hasitem("statsdb")) { string tmp = doc.getitemvaluestring("statsdb"); if(!"".equals(tmp)) { this.statsdb = tmp; } } if(doc.hasitem("systemmessagefr")) { string tmp = doc.getitemvaluestring("systemmessagefr"); if(!"".equals(tmp)) { this.systemmessagefr = tmp; } } if(doc.hasitem("systemmessageen")) { string tmp = doc.getitemvaluestring("systemmessageen"); if(!"".equals(tmp)) { this.systemmessageen = tmp; } } if(doc.hasitem("defaultlang")) { string tmp = doc.getitemvaluestring("defaultlang"); if(!"".equals(tmp)) { this.defaultlang = tmp; } } if(doc.hasitem("defaultprov")) { string tmp = doc.getitemvaluestring("defaultprov"); if(!"".equals(tmp)) { this.defaultprov = tmp; } } if(doc.hasitem("showprov")) { string tmp = doc.getitemvaluestring("showprov"); if(!"".equals(tmp)) { this.showprov = tmp; } } if(doc.hasitem("senderemail")) { string tmp = doc.getitemvaluestring("senderemail"); if(!"".equals(tmp)) { this.senderemail = tmp; } } if(doc.hasitem("sendername")) { string tmp = doc.getitemvaluestring("sendername"); if(!"".equals(tmp)) { this.sendername = tmp; } } if(doc.hasitem("appurl")) { string tmp = doc.getitemvaluestring("appurl"); if(!"".equals(tmp)) { this.appurl = tmp; } } if(doc.hasitem("emailtext")) { string tmp = doc.getitemvaluestring("emailtext"); if(!"".equals(tmp)) { this.emailtext = tmp; } } if(doc.hasitem("clicklinktext")) { string tmp = doc.getitemvaluestring("clicklinktext"); if(!"".equals(tmp)) { this.clicklinktext = tmp; } } if(doc.hasitem("emailfooter")) { string tmp = doc.getitemvaluestring("emailfooter"); if(!"".equals(tmp)) { this.emailfooter = tmp; } } if(doc.hasitem("messageintro")) { string tmp = doc.getitemvaluestring("messageintro"); if(!"".equals(tmp)) { this.messageintro = tmp; } } //allowratingmodification if(doc.hasitem("allowratingmodification")) { string tmp = doc.getitemvaluestring("allowratingmodification"); if(!"".equals(tmp)) { this.allowratingmodification = tmp; } } } } catch (notesexception e) { // todo auto-generated catch block e.printstacktrace(); } } /*****************************************************************************/ public int getnbwidgetfavorites() { return nbwidgetfavorites; } public void setnbwidgetfavorites(int nbwidgetfavorites) { this.nbwidgetfavorites = nbwidgetfavorites; } public int getnbwidgetmostpopular() { return nbwidgetmostpopular; } public void setnbwidgetmostpopular(int nbwidgetmostpopular) { this.nbwidgetmostpopular = nbwidgetmostpopular; } public int getnbwidgettoolbox() { return nbwidgettoolbox; } public void setnbwidgettoolbox(int nbwidgettoolbox) { this.nbwidgettoolbox = nbwidgettoolbox; } public void setnbwhatsnew(int nbwhatsnew) { this.nbwhatsnew = nbwhatsnew; } public int getnbwhatsnew() { return nbwhatsnew; } public void setshowdetailswhatsnew(string showdetailswhatsnew) { this.showdetailswhatsnew = showdetailswhatsnew; } public string getshowdetailswhatsnew() { return showdetailswhatsnew; } public int getnbsearchresults() { return nbsearchresults; } public void setnbsearchresults(int nbsearchresults) { this.nbsearchresults = nbsearchresults; } public int getnbmaxsearchresults() { return nbmaxsearchresults; } public void setnbmaxsearchresults(int nbmaxsearchresults) { this.nbmaxsearchresults = nbmaxsearchresults; } public string gethomepageunid_fr() { return homepageunid_fr; } public void sethomepageunid_fr(string homepageunid_fr) { this.homepageunid_fr = homepageunid_fr; } public string gethomepageunid_en() { return homepageunid_en; } public void sethomepageunid_en(string homepageunid_en) { this.homepageunid_en = homepageunid_en; } public string getappemailaddress() { return appemailaddress; } public void setappemailaddress(string appemailaddress) { this.appemailaddress = appemailaddress; } public string getsystemmessagefr() { return systemmessagefr; } public void setsystemmessagefr(string systemmessagefr) { this.systemmessagefr = systemmessagefr; } public string getsystemmessageen() { return systemmessageen; } public void setsystemmessageen(string systemmessageen) { this.systemmessageen = systemmessageen; } public void setstatsdb(string statsdb) { this.statsdb = statsdb; } public string getstatsdb() { return statsdb; } public void setdefaultlang(string defaultlang) { this.defaultlang = defaultlang; } public string getdefaultprov() { return defaultprov; } public void setdefaultprov(string defaultprov) { this.defaultprov = defaultprov; } public void setshowprov(string showprov) { this.showprov = showprov; } public string getshowprov() { return showprov; } public string getdefaultlang() { return defaultlang; } public string getmessageintro() { return messageintro; } public void setmessageintro(string messageintro) { this.messageintro = messageintro; } public string getsenderemail() { return senderemail; } public void setsenderemail(string senderemail) { this.senderemail = senderemail; } public string getsendername() { return sendername; } public void setsendername(string sendername) { this.sendername = sendername; } public string getappurl() { return appurl; } public void setappurl(string appurl) { this.appurl = appurl; } public string getemailtext() { return emailtext; } public void setemailtext(string emailtext) { this.emailtext = emailtext; } public string getclicklinktext() { return clicklinktext; } public void setclicklinktext(string clicklinktext) { this.clicklinktext = clicklinktext; } public string getemailfooter() { return emailfooter; } public void setemailfooter(string emailfooter) { this.emailfooter = emailfooter; } //allowratingmodification public string getallowratingmodification() { return allowratingmodification; } public void setallowratingmodification(string allowratingmodification) { this.allowratingmodification = allowratingmodification; } }
the variableresolver goes through implicit variables (e.g. session
, database
) scoped variables (e.g. applicationscope.myvar
). bean accessed ssjs via variableresolver.
so can use:
extlibutil.resolvevariable(facescontext.getcurrentinstance(), "myappscopebean");
Comments
Post a Comment