1 Reply Latest reply on Dec 14, 2007 8:55 AM by Julian Duque

    ReRender h:dataTable

    Dumitru Andrei Newbie

      Hi all,

      i have this problem with my variable columns constructed h:dataTable, that i am binding to a session scoped backing bean HtmlDataTable variable : when I change the columns of the dataTable in the backing bean and rerender the dataTable using ajax4jsf the columns don't get updated, but only the data inside the table. Columns only get updated after the whole page get's reloaded, and i don't know why ?

      This is my simplified jsf coding :

      in an a4j:form i have this button with an action that rebuilds the dataTable with the according data and column headers.

      <a4j:commandButton styleClass="button" value="Execute"
      action="#{viewsForm.executeQueryAndReloadTable}"
      reRender="resultsTable" />

      and the table looks like this

      <a4j:form id="resultsTableForm" ajaxSubmit="true" reRender="resultsTable">
      <h:dataTable id="resultsTable"
      rowClasses="rowOdd, rowEven"
      columnClasses="centered"
      binding="#{viewsModel.resultTableBean.dataTable}" >
      </h:dataTable>
      </a4j:form>

      and backing bean

      public void createTable(){
      HtmlDataTable dynamicDataTable = new HtmlDataTable();

      dynamicDataTable.setValueExpression("value",
      JSFUtil.createValueExpression("#{viewsModel.resultsTable.data}", javax.faces.model.ListDataModel.class));

      dynamicDataTable.setVar("dynamicItem");

      // Get amount of columns.
      int columns = headers.size();

      // Loop through columns.
      for (int i = 0; i < columns; i++) {

      logger.debug("Setting elements for column with header " + headers.get(i));

      // Create column.

      HtmlColumn column = new HtmlColumn();

      // Create header (optional) and add to column.

      HtmlOutputText header = new HtmlOutputText();

      header.setValue(headers.get(i));

      column.setHeader(header);

      // Create output and add to column.

      HtmlOutputText output = new HtmlOutputText();

      output.setValueExpression("value",
      JSFUtil.createValueExpression("#{dynamicItem[" + i + "]}", String.class));

      column.getChildren().add(output);

      // Add column to datatable.

      dynamicDataTable.getChildren().add(column);

      }

      this.setDataTable(dynamicDataTable);
      }


      To be more specific i will explicitly add this scenarios :

      I load the page ( the table is empty ) - I create a query - i press the execute button - the request is send and response received but the dataTable does not get rerendered accordingly. When i reload the whole page the table gets rendered exactly as it should. From this step I create another query ( so the result table will have some other columns ), press the execute button and the data in the dataTable get's refreshed (so I have a rerender) but the layout stays the same (the columns do not get changed) only the data inside get's assigned to the old table. When i reload the entire page again, the table is rendered correctly.

      Has anyone encountered this problem with a dataTable, or another binded component?

      Thanks in advance,

      Andrei