替换com.sun.faces.util.util.createConstantMethodBinding(字符串操作)



我正在进行一个从JSF 1.1到JSF 2.0的迁移项目,我的一个自定义组件有这段代码。

MethodBinding mb = com.sun.faces.util.Util.createConstantMethodBinding(
                        String action
                   );
((XYZComponent)component).setAction(mb);

由于这是来自Sunjar的,我在JSF 2.0中没有确切的替代品。如果我继续将其更改为createMethodExpression(..),这是一种正确的方法吗?

如果没有,请向我推荐另一种方法。

这是您的代码,但使用JSF MethodExpression。

            FacesContext fc = FacesContext.getCurrentInstance();
            ELContext elContext = fc.getELContext();
            String action = "#{bean.doSomeThing(id)}";
            Class<?>[] parameterTypes = new Class[1];
            parameterTypes[0]=String.class;
            Class<? extends String> returnType = String.class;
            MethodExpression me = fc.getApplication().getExpressionFactory().createMethodExpression(elContext,action, returnType, parameterTypes);
            component.setActionExpression(me);

相关内容

最新更新