我有一个动态创建的HtmlCommandLink
ActionListener
,但是当我点击链接时,动作监听器方法没有被调用。
代码:
public HtmlPanelGroup getP() {
p = new HtmlPanelGroup();
FacesContext ctx = FacesContext.getCurrentInstance();
HtmlCommandLink l = new HtmlCommandLink();
l.setTitle("Goto");
l.setImmediate(true);
l.addActionListener(new ComponenetListener());
//new ListenerTest());//new MethodExpressionActionListener(methodExpression) );
l.setValue("Go");
p.getChildren().add(l);
return p;
}
和监听器代码是
@ManagedBean
@SessionScoped
public class ComponenetListener implements ActionListener{
public ComponenetListener() {
String s="sridhar";
}
@Override
public void processAction(ActionEvent event) throws AbortProcessingException {
UIComponent eventComponent = event.getComponent();
System.out.println("test");
String strEventCompID = eventComponent.getId();
throw new UnsupportedOperationException("Not supported yet.");
}
}
答案 0 :(得分:1)
您必须为所有动态创建的输入和命令组件提供固定ID。
l.setId("yourID");
您还需要确保存在<h:form>
(或UIForm
)组件作为树父。