本文介绍了动态创建的HtmlCommandLink上未调用ActionListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态创建的HtmlCommandLinkActionListener,但是当我单击链接时,没有调用动作侦听器方法.

I have a dynamically created HtmlCommandLink with an ActionListener, but when I click on the link, the action listener method is not being called.

代码:

   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.");
       }
   }

推荐答案

您必须为所有动态创建的输入和命令组件赋予固定的ID.

You must give all your dynamically created input and command components a fixed ID.

l.setId("yourID");

您还需要确保存在作为树父级的<h:form>(或UIForm)组件.

You also need to ensure that there's a <h:form> (or UIForm) component present as tree parent.

这篇关于动态创建的HtmlCommandLink上未调用ActionListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 09:06