2011-02-01 74 views
0

我用下面的代碼intialized一個變量ServletContext聽衆:如何在jsf中獲取應用程序範圍變量?

sce.getServletContext().setAttribute("foo", "someValue"); 

所以,我現在可以使用下面的代碼獲取的價值:

FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("foo"); 

現在,我要訪問此值在其他一些不是FacesContext的課程中,或者不是控制器。我怎樣才能做到這一點?

回答

1

如果其他班級沒有在FacesContextServletContext中運行,那麼您根本就不能。

只要將它作爲構造函數或方法參數傳遞即可。

otherClass.doSomething(foo);