私はおそらくOmniFacesにあまりにも盲目で新しすぎて、バッキング Bean インスタンスを取得するための基本的なメソッドをAPIで見つけることができませんでした。そのような方法がある場合、どこで見つけることができますか? このように:
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());
}