【发布时间】:2013-04-26 12:44:57
【问题描述】:
我可能对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());
}
【问题讨论】:
-
<T extends Object>与<T>相同。