【发布时间】:2010-01-27 14:52:28
【问题描述】:
我必须动态创建一些 commandLinks 并为其附加一些动作侦听器,因此我将 <h:panelGrid> 放在 JSP 页面上并使用此类代码添加 commandLinks 并将动作侦听器分配给:
public ManagedBean(){
List<UIComponenet> child = panelGrid.getChilderen();
list.clear();
List<MyClass> myList = getSomeList();
for (MyClass myObj : myList){
FacesContext ctx = FacesContext.getCurrentContext();
HtmlCommandLink cmdLink = (HtmlCommandLink) ctx.getApplication.createComponent(HtmlCommandLink.COMPONENT_TYPE);
cmdLink.setValue(myObj.getName());
cmdLink.setActionLinstner(new ActionListener(){
public void processAction(ActionEvent event) throws AbortProcessingException{
System.out.println (">>>>>>>>>>>>>>>>>I am HERE ");
}
});
child.add(cmdLink);
}
}
但不幸的是,当我按下这个commandLinks 时,抛出了一个异常!如何在运行时添加组件事件监听器?
(注意,我上面的代码包含我刚刚写的语法/编译错误)。
【问题讨论】:
-
目前没有堆栈跟踪,但它应该可以工作吗?
标签: jsf