0 Replies Latest reply on Jul 11, 2012 3:47 PM by Ernesto Hernandez

    How to styling a rich:dataTable created at runtime?

    Ernesto Hernandez Newbie

      Hi guys!

       

      I'm creating a data table at runtime. It's working right now, but it does not have any style, just plain text, even when I'm giving it some classes availables in my CSS file.

       

      This is the Java code which I'm creating the dataTable with:

       

       

      private void populateDynamicDataTable() {
      
              dynamicHeaders = new String[] {"id", "description"};
              // Create <h:dataTable value="#{myBean.dynamicList}" var="dynamicItem">.
              UIDataTable dynamicDataTable = new UIDataTable();
              dynamicDataTable.setValueExpression("value",
                  createValueExpression("#{workListBean.columns}", List.class));
              dynamicDataTable.setVar("dynamicItem");
              
              // These are some style classes I have defined in my CSS file
              dynamicDataTable.setHeaderClass("order-table-header");
              dynamicDataTable.setStyleClass("order-table");
              dynamicDataTable.setRowClasses("order-table-odd-row,order-table-even-row");
      
              // Iterate over columns.
              for (int i = 0; i < dynamicHeaders.length; i++) {
      
                  // Create <h:column>.
                  UIColumn column = new UIColumn();
                  dynamicDataTable.getChildren().add(column);
      
                  // Create <h:outputText value="dynamicHeaders[i]"> for <f:facet name="header"> of column.
                  HtmlOutputText header = new HtmlOutputText();
                  header.setValue(dynamicHeaders[i]);
                  column.setHeader(header);
      
                  // Obtain the value
                  String col = dynamicHeaders[i];
                  // Create <h:outputText value="#{dynamicItem[" + i + "]}"> for the body of column.
                  HtmlOutputText output = new HtmlOutputText();
                  output.setValueExpression("value",
                      createValueExpression("#{dynamicItem." + col + "}", String.class));
                  column.getChildren().add(output);
                  
              }
              
              UIColumn column = new UIColumn();
              dynamicDataTable.getChildren().add(column);
              // Create <h:commandLink value="#{dataItem.id}" action="#{myBean.editPopulatedDataItem}" />
              // for the body of 'ID' column.
              HtmlCommandLink idLink = new HtmlCommandLink();
              idLink.setValue("Iniciar tarea");
              idLink.setActionExpression(createActionExpression("#{busquedas.initTask}", String.class));
              column.getChildren().add(idLink);
              
      
              // Add the datatable to <h:panelGroup binding="#{myBean.dynamicDataTableGroup}">.
              dynamicDataTableGroup = new UIPanel();
              dynamicDataTableGroup.getChildren().add(dynamicDataTable);
              
          }
      

       

      This is the JSF file:

       

       

       

      Does anybody know what am I missing?

       

      Thanks in advance!