开发者

ActionListener is not being called on dynamically created HtmlCommandLink

开发者 https://www.devze.com 2023-04-01 07:54 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消