ActionListener is not being called on dynamically created HtmlCommandLink
I have a dynamically created HtmlCommandLink
with an ActionListener
, but when I click on the link, the action listener开发者_如何学JAVA method is not being called.
Code:
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;
}
and listener code is
@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.");
}
}
You must give all your dynamically created input and command components a fixed ID.
l.setId("yourID");
You also need to ensure that there's a <h:form>
(or UIForm
) component present as tree parent.
精彩评论