1
我可能对于OmniFaces太盲目,太新,并且在API中找不到检索辅助bean实例的基本方法。哪里可以找到这样一种方法?像这样的:OmniFaces中的getBackingBean()
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-26 13:41:36