我写了这样一个方法:
public HtmlCommandLink newCommandLink(String id,String value,String ActionListener,UIParameter[] params){
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
MethodBinding mBinding = app.createMethodBinding(ActionListener,new Class[0]);
HtmlCommandLink cl = new HtmlCommandLink();
cl.setId(id);
cl.setValue(value);
cl.setActionListener(mBinding);
cl.setImmediate(true);
for(int i=0;i<params.length;i++){
cl.getChildren().add(params[i]);
}
return cl;
}
程序中这样调用了这个方法:
public void addComponents(){
FacesContext context = FacesContext.getCurrentInstance();
UIParameter[] params = new UIParameter[1];
UIParameter param = new UIParameter();
param.setName("ndx");
param.setValue("2007");
params[0]=param;
HtmlCommandLink cl = this.newCommandLink("test111", "测试", "#{customerBean.test}", params);
UIViewRoot vr = context.getViewRoot();
UIComponent table = vr.findComponent("form1:menu"); 
table.getChildren().add(cl);
}
生成的超链接组件和
<h:commandLink value="测试1" actionListener="#{customerBean.test}">
<f:param name="nd1" value="2008"></f:param>
</h:commandLink>
有什么区别吗?为什么程序中调用addComponents生成的commandLink执行时出错(提示:javax.faces.el.MethodNotFoundException: test: com.CustomerBean.test())而页面中直接写的这个commandLink 就没问题啊?