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

删除回忆录丶 提交于 2019-12-05 20:42:49

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/6772270/jsf-1-x-valuebinding-is-deprecated-what-is-the-correct-replacement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!