1 Reply Latest reply on Nov 20, 2007 9:49 AM by inv3r53 d

    How to create datatable through code in bean??

    Tomislav Tkal?evi? Novice

      I am trying to get this to work...

      
       @In(required=false,create=true)
       @Out(required=false)
       HtmlDataTable tablica;
      
       public void testNapuni(){
       HtmlColumn kolona2 = new HtmlColumn();
      
       HtmlOutputText text2 = new HtmlOutputText();
       text2.setValue("Druga kolona");
      
       kolona2.getChildren().add(text2);
      
       tablica.setRows(2);
       // DataModel
       ListDataModel listDataModel = new ListDataModel();
      
       ArrayList list = new ArrayList();
       list.add(kolona1);
       list.add(kolona2);
       listDataModel.setWrappedData(list);
       tablica.setValue(listDataModel);
       }
      
      


      And in jsp page just tried to bind it with table in the bean...
      Can't get it to work...


        • 1. Re: How to create datatable through code in bean??
          inv3r53 d Novice

          i found this on searching ..

          public UIData getDataTable()
          {
          UIColumn col;
          UIOutput out = null;
          Application app = FacesContext.getCurrentInstance().getApplication();
          
          int colCount = 3;
          
          for(int j = 0; j < colCount; ++j) {
          out = new UIOutput();
          col = new UIColumn();
          ValueBinding vb = app.createValueBinding("#{" + j + "}"); //create el expression
          out.setValueBinding("value", vb);
          out.setRendererType("javax.faces.Text");
          col.getChildren().add(out);
          dataTable.getChildren().add(col);
          }
          
          return dataTable;
          
          }