如何在jsf中获取应用程序范围变量? [英] How to get application scope variable in jsf?
本文介绍了如何在jsf中获取应用程序范围变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已使用以下代码在ServletContext
侦听器中初始化了一个变量:
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().getExternalContext().getApplicationMap().get("foo");
现在,我想在不是FacesContext
或控制器的其他某些类中访问此值.我该怎么办?
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?
推荐答案
如果另一个类不在FacesContext
或ServletContext
中运行,则根本无法运行.
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);
这篇关于如何在jsf中获取应用程序范围变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文