0 Replies Latest reply on Jun 21, 2012 4:14 PM by relliknomed

    ActionListeners not triggered inside a dynamic column in rich:dataTable.

    relliknomed

      I'm creating columns dinamically inside my component, the datatable then it's rendered correctly with the new columns, however actionListeners declared inside them are not executed. I have even checked that the component it's sending a request to the server... but it's like there were no action listener defined. Here's the code that I used to create the table, what could be wrong???.

       

      public void addColumns(){
         
      UIDataTable dataTable = (UIDataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("frmAdmArt:dtArtResult");
         
      for(int i=0;i<2;i++){
                 
      UIColumn column = (UIColumn) FacesContext.getCurrentInstance().getApplication().createComponent(UIColumn.COMPONENT_TYPE);              
                 
      if(i==0){
                      column
      .setStyle("width:36.5px;white-space:nowrap;");
                     
      HtmlOutputText  values = (HtmlOutputText) FacesContext.getCurrentInstance().getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
                      values
      .setValue("No"+i);
                      column
      .getChildren().add(values);
                 
      }
                 
      if(i==1){
                      column
      .setStyle("width:151px;white-space:nowrap;");
                     
      UICommandLink commandLink =  (UICommandLink) FacesContext.getCurrentInstance().getApplication().createComponent(UICommandLink.COMPONENT_TYPE);
                      commandLink
      .addActionListener(getMethodExpressionActionListener("mymanagedBean.verDetalleArticulo"));
                      commandLink
      .setValueExpression("value", createValueExpression("#{!empty detalle.codigoBarrasActivo.id.codigoBarras ? detalle.codigoBarrasActivo.id.codigoBarras : '----'}", String.class));
                      commandLink
      .setTitle("Detalle artículo");
                      commandLink
      .setExecute("@this");
                      commandLink
      .setImmediate(true);
                      commandLink
      .setId("verDetalle");          

                      column
      .getChildren().add(commandLink);
                 
      }      
                  column
      .setId("col"+i);
                  dataTable
      .getChildren().add(i, column);
         
      }  
      }  
      private MethodExpressionActionListener getMethodExpressionActionListener(String method){
         
      FacesContext facesContext = FacesContext.getCurrentInstance(); 
         
      return new MethodExpressionActionListener(facesContext.getApplication().getExpressionFactory().createMethodExpression(FacesContext.getCurrentInstance().getELContext(),
                 
      "#{" + method + "}", Void.TYPE, new Class[] { ActionEvent.class }));
      }

       

      private ValueExpression createValueExpression(String valueExpression, Class<?> valueType) {              

                    FacesContext facesContext = FacesContext.getCurrentInstance();

                   return facesContext.getApplication().getExpressionFactory().createValueExpression( 

                            facesContext.getELContext(), valueExpression, valueType); 

                }