不建议使用JSF 1.x ValueBinding,正确的替换方法是什么? [英] JSF 1.x ValueBinding is deprecated, what is the correct replacement?

查看:166
本文介绍了不建议使用JSF 1.x ValueBinding,正确的替换方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些JSF 1.0/1.1代码:

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

从JSF 1.2开始,已弃用 ValueBinding并替换为ValueExpression .我不确定如何更改上述代码才能使用ValueExpression.

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.

推荐答案

零件

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

另请参见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆