2011-06-24 55 views
0

我们最近从JSF 1.2升级到2.1。我们在WebSphere 6.1上运行,其具有的Servlet 2.4使用Servlet 2.4访问JSF2.1中的另一个托管Bean

我们使用以下库: MyFaces的2.1.1 EL-API 2.2

现在我们唯一的问题是,我们不能访问其他备份豆类就像我们之前做过的:

public static Object getBackingBean(String pName) { 
    ELContext elContext = FacesContext.getCurrentInstance().getELContext(); 
    Object ret = elContext.getELResolver().getValue(elContext, null, pName); 
    return ret; 
} 

这将始终返回null。 我们也试过:

Beanclass bean = (Beanclass) FacesContext.getCurrentInstance().getApplication() 
.getELResolver().getValue(elContext, null, "beanclass"); 

哪些返回null。

我们已经尝试了@ManagedProperty注释,但这显然是一个Servlet 2.5功能。默认情况下,ELContext是否可能使用DI?有没有办法在JSF2.1和Servlet 2.4中获得另一个支持Bean的实例?谢谢!

回答

1

正如你可以在阅读the MyFaces webpage

JSF 2.1需要Java 1.5或更高版本,JSP 2.1,JSTL 1.2和的Java Servlet 2.5实施。

0

诚然,正式的JSF 2.1需要这样做,但理论上可以使用JSP 2.0运行MyFaces Core 2.1。如果您可以使用MyFaces Core 1.2.x运行应用程序,那么您可以使用2.1来执行该应用程序,因为没有技术上的原因导致无法运行。尝试询问MyFaces Users List。我做了一个检查,并且有一些用户在WebSphere 6.1上运行1.2.x应用程序,所以也许你可以在那里有更好的运气。

+0

谢谢 - 我已经交叉发布它在MyFaces用户列表 – toby

2

我只是想用正确的答案跟进我自己的问题 - 即使Servlet 2.5是必需的,我的任务也可以在没有它的情况下实现。这里是如何可靠地得到sessionBean的实例:

BeanClass beanInst = (BeanClass) JSF2Util.findBean("beanClass"); 

public static <T> T findBean(String beanName) { 
    FacesContext facesContext = FacesContext.getCurrentInstance(); 
    Application app = facesContext.getApplication(); 
    ExpressionFactory elFactory = app.getExpressionFactory(); 
    ELContext elContext = facesContext.getELContext(); 
    ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{" + beanName + "}",Object.class); 
    return (T) valueExp.getValue(elContext); 
} 
相关问题