我可能太盲目了,对OmniFaces也太陌生了,在API中找不到一个基本的方法来检索支持bean实例。如果有这样的方法,我在哪里可以找到呢?就像这样:
public static Object getBackingBean(String name) {
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
ValueExpression expression = app.getExpressionFactory()
.createValueExpression(context.getELContext(), String.format("#{%s}", name), Object.class);
return expression.getValue(context.getELContext());
}或者使用泛型的更动态的版本:
public static <T> T getBackingBean(String name) {
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
ValueExpression expression = app.getExpressionFactory()
.createValueExpression(context.getELContext(), String.format("#{%s}", name), Object.class);
return (T) expression.getValue(context.getELContext());
}发布于 2013-04-28 03:13:50
我们有一个几乎类似的方法,但它可以计算(并获得)任何类型的表达式,而不仅仅是一个简化的根表达式。
我是Faces.evaluateExpressionGet。
您可以按如下方式使用它:
MyBean myBean = Faces.evaluateExpressionGet("#{myBean}");其中MyBean例如定义如下:
@ViewScoped
@ManagedBean
public class MyBean {
// ...
}https://stackoverflow.com/questions/16236810
复制相似问题