1 Reply Latest reply on Feb 18, 2013 2:46 PM by rodmarcm

    UIDataTable and JSF component binding

    jmanko

      I'm working on a getting a dynamic table coded, but it doesn't seem to work.  I define a rich:dataTable with a binding to a backing bean property of type UIDataTable, but no columns appear after adding them through code.

       

      Page:

      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:h="http://java.sun.com/jsf/html"
                      template="/WEB-INF/include/main-template.xhtml"
                      xmlns:rich="http://richfaces.org/rich"
                      xmlns:f="http://java.sun.com/jsf/core"
                      xmlns="http://www.w3.org/1999/xhtml"
                      xmlns:a4j="http://richfaces.org/a4j">
          <ui:define name="left">
              <h:form>
                  <rich:panel style="text-align: center">
                      <h:commandButton value="Search" action="#{listController.searchForList()}" styleClass="searchButton"  />
                  </rich:panel>
              </h:form>
          </ui:define>
          <ui:define name="content">
              <rich:panel id="resultsPanel" header="Results">
                  test before
                  <rich:dataTable id="resultsTable"  binding="#{listController.list}"/>
                  test after
              </rich:panel>
          </ui:define>
      </ui:composition>
      

       

       

      Managed bean:

      @Named
      @SessionScoped
      public class ListController implements Serializable {
      
          @EJB
          private SessionSearchBeanLocal searchBean;
          private UIDataTable list;
      
          public void searchForList() {
              list = searchBean.findList();
          }
      
          public UIDataTable getList() {
              return list;
          }
      
          public void setList(UIDataTable list) {
              this.list = list;
          }
      }
      

       

      EJB:

      @Stateless
      public class SessionSearchBean implements SessionSearchBeanLocal {
      
          @PersistenceContext
          private EntityManager em;
      
          @Override
          public UIDataTable findList() {
              FacesContext fc = FacesContext.getCurrentInstance();
              Application app = fc.getApplication();
              ExpressionFactory exp = app.getExpressionFactory();
      
              UIDataTable dataTable = (UIDataTable) app.createComponent(UIDataTable.COMPONENT_TYPE);
              UIColumnGroup headerColumnGroup =  (UIColumnGroup) app.createComponent(UIColumnGroup.COMPONENT_TYPE);
              UIColumn column;
              HtmlOutputText output;
      
              dataTable.getChildren().add(headerColumnGroup);
              dataTable.setId("resultsDataTable");
              dataTable.setColumnClasses("columsClasses");
      
              column = (UIColumn) app.createComponent(UIColumn.COMPONENT_TYPE);
              output = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
              output.setValue("Name");
              column.getChildren().add(output);
              headerColumnGroup.getChildren().add(column);
      
              column = (UIColumn) app.createComponent(UIColumn.COMPONENT_TYPE);
              output = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
              output.setValue("Street Address");
              column.getChildren().add(output);
              headerColumnGroup.getChildren().add(column);
      
              column = (UIColumn) app.createComponent(UIColumn.COMPONENT_TYPE);
              output = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
              output.setValue("G");
              column.getChildren().add(output);
              headerColumnGroup.getChildren().add(column);
      
              column = (UIColumn) app.createComponent(UIColumn.COMPONENT_TYPE);
              output = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
              output.setValue("A");
              column.getChildren().add(output);
              headerColumnGroup.getChildren().add(column);
      
              column = (UIColumn) app.createComponent(UIColumn.COMPONENT_TYPE);
              output = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
              output.setValue("P");
              column.getChildren().add(output);
              headerColumnGroup.getChildren().add(column);
      
              column = (UIColumn) app.createComponent(UIColumn.COMPONENT_TYPE);
              output = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
              output.setValue("S");
              column.getChildren().add(output);
              headerColumnGroup.getChildren().add(column);
      
              column = (UIColumn) app.createComponent(UIColumn.COMPONENT_TYPE);
              output = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
              output.setValue("Reg Date");
              column.getChildren().add(output);
              headerColumnGroup.getChildren().add(column);
      
              column = (UIColumn) app.createComponent(UIColumn.COMPONENT_TYPE);
              column.setColspan(7);
              output = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
              output.setValue("Z");
              output.setParent(column);
              column.getChildren().add(output);
              dataTable.getChildren().add(column);
      
              return dataTable;
      
          }
      }