开发者

How to get application scope variable in jsf?

开发者 https://www.devze.com 2023-02-07 17:41 出处:网络
I\'ve intialized a variable in ServletContext listener using the following code: sce.getServletContext().setAttribute(\"foo\", \"someValue\");

I've intialized a variable in ServletContext listener using the following code:

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

So, I can now get the value using following code:

FacesContext.getCurrentInstance().ge开发者_开发知识库tExternalContext().getApplicationMap().get("foo");

Now, I want to access this value in some other class that is not a FacesContext, or is not a controller. How can I do that?


If the other class is not running in FacesContext or ServletContext, then you simply can't.

Just pass it as constructor or method argument.

otherClass.doSomething(foo);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号