2 Replies Latest reply: Jan 15, 2010 2:06 PM by 807575 RSS

    Dynamic tables and ListDataProvider

    807575
      Hello creator folk,

      I have to dynamicaly generate a table, whom data are not coming from a database but from a list of "Efficiency" objects. So I've read the formidable post by Winston Prakash, here: http://blogs.sun.com/winston/entry/creating_dynamic_table.

      Here are my Efficiency object, quite simple:
      public class Efficiency {
          
          private String abbr;
          private double eff;
          
          /** Creates a new instance of Efficiency */
          public Efficiency(String abbr, double eff) {
              this.abbr = abbr;
              this.eff = eff;
          }
      
          public String getAbbr() {
              return abbr;
          }
      
          public double getEff() {
              return eff;
          }
      And here is the extract of prerender() where I compute the table:
                  
                  ArrayList listEff = new ArrayList();
                  // skipping listEff generation. listEff is a list of Efficiency
                  // ...
                  // ...
      
                  listDataProvider = new ListDataProvider(listEff);
                  // I checked in the debugger, both listEff and listDataProvider got well filled
                  
                  //Create the Table Dynamically
                  Table table = new Table();
                  table.setId("table_" + zoneName);
                  table.setTitle(zoneName);
                  table.setAugmentTitle(false);
                  
                  // Create the Table Row group dynamically
                  TableRowGroup rowGroup = new TableRowGroup();
                  rowGroup.setId("rowGroup_" + zoneName);
                  rowGroup.setSourceVar("currentRow");
                  rowGroup.setValueBinding("sourceData", getApplication().
                  createValueBinding("#{Page1.listDataProvider}"));
                  
                  // Add the table row group to the table as a child
                  table.getChildren().add(rowGroup);
                  
                  // Create the first table Column
                  TableColumn tableColumn1 = new TableColumn();
                  tableColumn1.setId("tableColumnAbbr_" + zoneName);
                  tableColumn1.setHeaderText("Abbr");
                  
                  // Add the first table Column to the table row group
                  rowGroup.getChildren().add(tableColumn1);
                  
                  // Create the Static text and set its value as TRIPID
                  StaticText staticText1 = new StaticText();
                  staticText1.setValueBinding("text", getApplication().
                          createValueBinding("#{currentRow.abbr}"));
                  
                  // Add the static text to the table column1
                  tableColumn1.getChildren().add(staticText1);
                  
                  // Create the second table Column
                  TableColumn tableColumn2 = new TableColumn();
                  tableColumn2.setId("tableColumnEff_" + zoneName);
                  tableColumn2.setHeaderText("Efficacit´┐Ż");
                  
                  // Add the second table Column to the table row group
                  rowGroup.getChildren().add(tableColumn2);
                  
                  // Create the Static text and set its value as DEPDATE
                  StaticText staticText2 = new StaticText();
                  staticText2.setValueBinding("text", getApplication().
                          createValueBinding("#{currentRow.eff}"));
                  
                  // Add the Static Text2 to the table column2
                  tableColumn2.getChildren().add(staticText2);
                  
                  gridPanel1.getChildren().add(table);
      The result of the above code can be seen here: http://img151.imageshack.us/img151/9476/dynamictablebq9.png
      No data are found. As I said in the code comment, in the debugger I see that listDataProvider contains my data.

      My understanding is that my value binding expressions are not correct. Could you provide me a hint please?