5 Replies Latest reply on Jun 4, 2007 12:56 PM by Yevgen Tester

    DataTable with controls (update state)

    Yevgen Tester Newbie

      Hi,

      i'm using richtfaces 3.0.0 (java 1.5, Tomcat 5.5)

      Trying to create an datatable with 1 row, 1 column (with HtmlInput).
      In future of course will be more rows and columns :)

      My jsp

      ...
      <h:form>
       <rich:dataTable binding="#{jobsBean.table}"/ >
       <h:commandButton action="back" value="Submit" />
      </h:form>
      ...
      


      My JobsBean
      public class JobsBean
      {
       private HtmlDataTable table = null;
       private List list = null;
      
       public class TestClass
       {
       String text;
      
       public String getText() { return text; }
       public void setText(String text) { this.text = text; }
       }
      
       public JobsBean()
       {
       this.list = new ArrayList();
       this.list.add(new TestClass());
       }
      
       public HtmlDataTable getTable()
       {
       return table;
       }
      
       public void setTable(HtmlDataTable table)
       {
       this.table = table;
       if (this.created == false)
       {
       createTable();
       this.created = true;
       }
       }
      
       private void createTable()
       {
       Application application = FacesContext.getCurrentInstance()
       .getApplication();
      
       this.table.setColumns(1);
       this.table.setVar( "job" );
      
       ValueBinding vb = application.createValueBinding("#{job.text}");
       HtmlColumn column = (HtmlColumn) application
       .createComponent(HtmlColumn.COMPONENT_TYPE);
       HtmlInputText input = (HtmlInputText) application
       .createComponent(HtmlInputText.COMPONENT_TYPE);
       input.setValueBinding("value", vb);
       column.getChildren().add(input);
       input.setImmediate(true);
       this.table.getChildren().add(column);
      
       ValueBinding value = application.createValueBinding("#{jobsBean.list}");
       this.table.setValueBinding("value", value);
       }
      
       public List getList() { return list; }
       public void setList(List list) { this.list = list; }
      


      And ... nothing happens. If i entered the text into the editor and press button ... the page refreshed but the editor is empty.

      Very interesting if i add the column and editor not from the bean, but simple in the jsp page, like
       <rich:dataTable binding="#{jobsBean.table}" var="job" >
       <h:column>
       <h:inputText value="#{job.text}" />
       </h:column>
       </rich:dataTable>
      


      it works!
      There is the difference between adding dynamicly (from the bean) and static (jsp)