title: Dynamic datatable for columns and rows jsf (JSF2)
body: <p>I actually followed below link added columns and row data as dynamic, little confused on how to show on xhtml. any help</p>
  
  <p><a href="http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable" rel="nofollow">http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable</a></p>
  
  <pre><code>List&lt;String&gt; strlist = new ArrayList&lt;String&gt;();
          List&lt;List&lt;String&gt;&gt; dynamicListynamicList = new ArrayList&lt;List&lt;String&gt;&gt;();
          strlist.add("Name");
          strlist.add("SSN");
           for(String columnName : columnNamesList){
               strlist.add(columnName);
      }
  
           List&lt;String&gt; rowData = new ArrayList&lt;String&gt;();
           for(String otherList : listData){
               try {
                   rowData.add(otherList.getName());
                   rowData.add(otherList.getId());
                      if(otherList.getAmount() != null){
                           for(BigDecimal amount : otherList.getAmount()){
                               if(amount != null){
                                   rowData.add(amount.toString());
                               }else{
                                   rowData.add("");
                               }
                           }
                      }else{
                          for(String s : strlist){
                               rowData.add("");
                          }
                      }
  
                   } catch (Exception e) {
                      // TODO: handle exception
                       e.printStackTrace();
                  }
                   dynamicListynamicList.add(Arrays.asList(rowData.toArray(new String[rowData.size()] )));
              }
  
          String[] strarray = new String[strlist.size()];
          dynamicHeaders =   strlist.toArray(strarray );
          populateDynamicDataTable(dynamicListynamicList);
  
          private void populateDynamicDataTable(List&lt;List&lt;String&gt;&gt; dynamicList2){
               HtmlDataTable dynamicDataTable = new HtmlDataTable();
               for (int i = 0; i &lt; dynamicList2.get(0).size(); i++) {
                   HtmlColumn column = new HtmlColumn();
                   dynamicDataTable.getChildren().add(column);
                   HtmlOutputText header = new HtmlOutputText();
                      header.setValue(createValueExpression("#{dynamicItemColumn[" + dynamicHeaders[i] + "]}", String.class));
                      column.setHeader(header);
                      HtmlOutputText output = new HtmlOutputText();
                      output.setValueExpression("value",
                          createValueExpression("#{dynamicItem[" + i + "]}", String.class));
                      column.getChildren().add(output);
               }
  
               dynamicDataTableGroup = new HtmlPanelGroup();
               dynamicDataTableGroup.getChildren().add(dynamicDataTable);
               setDynamicList(dynamicList2);
  </code></pre>
  
  <p>every thing works fine as data being added, now i wasnt sure and my apologies, how to iterate in jsf page(xhtml), to show relvant columna nd rowdata..</p>