不推荐使用JSF 1.x ValueBinding,正确的替换是什么?

时间:2011-07-21 06:45:31

标签: jsf binding deprecated

我有一些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

1 个答案:

答案 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);

另见: