我有一些JSF 1.0 / 1.1代码:
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding vb = context.getApplication().createValueBinding("#{someBean}");
SomeBean sb = (SomeBean) vb.getValue(context);
自JSF 1.2以来,ValueBinding
is deprecated and replaced by ValueExpression
。我不确定如何更改上述代码才能使用ValueExpression
。
答案 0 :(得分:16)
部分
ValueBinding vb = context.getApplication().createValueBinding("#{someBean}");
SomeBean sb = (SomeBean) vb.getValue(context);
应替换为
ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), "#{someBean}", SomeBean.class);
SomeBean sb = (SomeBean) ve.getValue(context.getELContext());
或更好
SomeBean bc = context.getApplication().evaluateExpressionGet(context, "#{someBean}", SomeBean.class);