9

I have some JSF 1.0/1.1 code:

FacesContext context = FacesContext.getCurrentInstance();
ValueBinding vb = context.getApplication().createValueBinding("#{someBean}");
SomeBean sb = (SomeBean) vb.getValue(context);

Since JSF 1.2, ValueBinding is deprecated and replaced by ValueExpression. I'm not sure how to change the above code in order to use ValueExpression.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
senzacionale
  • 20,448
  • 67
  • 204
  • 316

1 Answers1

18

The part

ValueBinding vb = context.getApplication().createValueBinding("#{someBean}");
SomeBean sb = (SomeBean) vb.getValue(context);

should be replaced by

ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), "#{someBean}", SomeBean.class);
SomeBean sb = (SomeBean) ve.getValue(context.getELContext());

or, better

SomeBean bc = context.getApplication().evaluateExpressionGet(context, "#{someBean}", SomeBean.class);

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555