Reputation: 21
We have recently upgraded from JSF 1.2 to 2.1. We are running on WebSphere 6.1 which has Servlet 2.4
We are using the following libraries: myfaces 2.1.1 el-api-2.2
Now the only problem we have is that we cannot access the other Backing Beans like we did before with:
public static Object getBackingBean( String pName ) {
ELContext elContext = FacesContext.getCurrentInstance().getELContext();
Object ret = elContext.getELResolver().getValue(elContext, null, pName);
return ret;
}
This will always return null. We have also tried:
Beanclass bean = (Beanclass) FacesContext.getCurrentInstance().getApplication()
.getELResolver().getValue(elContext, null, "beanclass");
which return null as well.
We have tried the @ManagedProperty annotation but this is apparently a Servlet 2.5 feature. Is it possible that the ELContext uses DI now by default? Is there a way to get an Instance of another backing Bean in JSF2.1 and Servlet 2.4? Thanks!
Upvotes: 0
Views: 1386
Reputation: 21
I just wanted to follow up my own question with the correct answer - even though Servlet 2.5 is required my task can be archieved without it. Here is how to reliably get the Instance of a 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);
}
Upvotes: 2
Reputation: 2318
It is true that officially JSF 2.1 requires that, but in theory it is possible to run MyFaces Core 2.1 with JSP 2.0. If you can run an application with MyFaces Core 1.2.x, there are chances you can do it with 2.1, because there are no technical reasons why that can't run. Try ask on MyFaces Users List. I did a check and there are users who runs 1.2.x applications on WebSphere 6.1, so maybe you can have better luck there.
Upvotes: 0
Reputation: 3974
As you can read on the MyFaces webpage:
JSF 2.1 requires java 1.5 or later, JSP 2.1, JSTL 1.2 and a Java Servlet 2.5 implementation.
Upvotes: 1