开发者

JSF 1.x ValueBinding is deprecated, what is the correct replacement?

开发者 https://www.devze.com 2023-03-22 10:02 出处:网络
I have some JSF 1.0/1.1 code: FacesContext context = FacesContext.getCurrentInstance(); ValueBinding vb = context.getApplication().createValueBinding(\"#{someBean}\");

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 c开发者_C百科hange the above code in order to use ValueExpression.


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:

  • Get JSF managed bean by name in any Servlet related class
  • How to create dynamic JSF form fields
0

精彩评论

暂无评论...
验证码 换一张
取 消