2011-09-02 44 views
2

我有一个动态创建的HtmlCommandLinkActionListener,但是当我点击链接时,动作侦听器方法没有被调用。动态创建的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."); 
     } 
    } 

回答

1

你必须给所有的动态创建的输入和命令组件固定ID。

l.setId("yourID"); 

你还需要确保有存在树父<h:form>(或UIForm)组成。

+0

感谢您的回复或有任何更改要求 –

+0

非常感谢您的回复工作 –

相关问题