Jsf OmniFaces中的getBackingBean()

Jsf OmniFaces中的getBackingBean(),jsf,omnifaces,Jsf,Omnifaces,我可能太盲目,太新了,无法在中找到一个基本方法来检索支持bean实例。如果有这样的方法,我在哪里可以找到?像这个: 公共静态对象getBackingBean(字符串名称){ FacesContext context=FacesContext.getCurrentInstance(); 应用程序app=context.getApplication(); ValueExpression=app.getExpressionFactory() .createValueExpression(context

我可能太盲目,太新了,无法在中找到一个基本方法来检索支持bean实例。如果有这样的方法,我在哪里可以找到?像这个:

公共静态对象getBackingBean(字符串名称){
FacesContext context=FacesContext.getCurrentInstance();
应用程序app=context.getApplication();
ValueExpression=app.getExpressionFactory()
.createValueExpression(context.getELContext(),String.format(“#{%s}”,name),Object.class);
返回表达式.getValue(context.getELContext());
}
或更具动态性的泛型版本:

公共静态T getBackingBean(字符串名称){ FacesContext context=FacesContext.getCurrentInstance(); 应用程序app=context.getApplication(); ValueExpression=app.getExpressionFactory() .createValueExpression(context.getELContext(),String.format(“#{%s}”,name),Object.class); return(T)expression.getValue(context.getELContext()); }
我们有一个类似的方法,但它可以计算(并得到)任何类型的表达式,而不仅仅是一个简化的根表达式

是的

您可以按如下方式使用它:

MyBean myBean = Faces.evaluateExpressionGet("#{myBean}");
@ViewScoped
@ManagedBean
public class MyBean {
    // ...
}
例如,
MyBean
定义如下:

MyBean myBean = Faces.evaluateExpressionGet("#{myBean}");
@ViewScoped
@ManagedBean
public class MyBean {
    // ...
}
相同。