MyFaces Core
  1. MyFaces Core
  2. MYFACES-3518

Datatable (h:dataTable) is not populated with data despite getAll() method returns ResultSet with table rows ( Using Tomcat 7 + MySQL 5.5 + mysql-connector-java-5.1.18 )

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.6
    • Fix Version/s: 1.1.10, 1.2.12, 2.0.13, 2.1.7
    • Component/s: General
    • Labels:
      None
    • Environment:
      Windows 7 64bit
      Tomcat 7.0.26
      myfaces-2.1.6
      JRE 6
      MySQL 5.5
      mysql-connector-java-5.1.18

      Description

      Hello, when I use the following BeanClass and xhtml page, Datatable is not populated with data, despite the method getAll() returns ResultSet that contains customer names.
      Code line System.out.println(crs.getString("Name")) iterates through the ResultSet and prints customer names from customer table before the ResultSet is being returned to h:dataTable component. This is what I get in Tomcat log:

      ..........

      *******************************************************************

          • WARNING: Apache MyFaces-2 is running in DEVELOPMENT mode. ***
          • ^^^^^^^^^^^ ***
          • Do NOT deploy to your live server(s) without changing this. ***
          • See Application#getProjectStage() for more information. ***
            *******************************************************************

      29/03/2012 22:19:57 org.apache.coyote.AbstractProtocol start
      INFO: Starting ProtocolHandler ["http-bio-8080"]
      29/03/2012 22:19:57 org.apache.coyote.AbstractProtocol start
      INFO: Starting ProtocolHandler ["ajp-bio-8009"]
      29/03/2012 22:19:57 org.apache.catalina.startup.Catalina start
      INFO: Server startup in 4706 ms
      29/03/2012 22:19:58 org.apache.myfaces.util.ExternalSpecifications isUnifiedELAvailable
      INFO: MyFaces Unified EL support enabled

      Start of Debug

      William Dupont
      William Dupont

      End of Debug

      This is the ManagedBean:

      package com.corejsf;

      import java.sql.Connection;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Statement;
      import javax.annotation.Resource;
      import javax.faces.bean.*;
      import javax.sql.DataSource;
      import javax.sql.rowset.CachedRowSet;

      @ManagedBean
      @RequestScoped

      public class CustomerBean {

      @Resource(name="jdbc/Sufa") private DataSource ds;

      public ResultSet getAll() throws SQLException {

      Connection conn = ds.getConnection();
      try {

      Statement stmt = conn.createStatement();
      ResultSet result = stmt.executeQuery("SELECT * FROM customers");
      CachedRowSet crs = new com.sun.rowset.CachedRowSetImpl();
      crs.populate(result);

      System.out.println("Start of Debug");

      while(crs.next())

      { System.out.println(crs.getString("Name")); }

      System.out.println("End of Debug");

      return crs;

      } finally

      { conn.close(); }

      }
      }

      This is xhtml page:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
      <h:body>
      <h:form>

      <h:dataTable value="#

      {customerBean.all}

      " var="customer">
      <h:column>
      <f:facet name="header">#

      {msgs.nameHeader}

      </f:facet>
      #

      {customer.Name}

      </h:column>
      </h:dataTable>

      </h:form>
      </h:body>
      </html>

      It's important to mention that the same code works perfect when I change JSF implementation to mojarra-2.1.7.
      It's seems like a bug.

      Thanks a lot

      Sagi

        Issue Links

          Activity

          Hide
          Leonardo Uribe added a comment -

          I checked the code and I finally found the problem. Since 1.1, myfaces DataModel classes assume rowCount is always defined. Recently, in MYFACES-3270, I found on the spec that rowCount can be -1, but that only means the model doesn't know how many rows are. ResultSetDataModel returns in getRowCount() by default -1.

          In MyFaces 1.1.3, a change was done in h:dataTable renderer to include "newspaper" mode in tomahawk. For such mode, get the rowCount is critical, because otherwise there is no way to calculate the newspaper rows and newspaper columns.

          The solution is add some code to iterate when getRowCount() returns -1.

          This issue will be fixed on 1.1.x, 1.2.x, 2.0.x and 2.1.x branches.

          Show
          Leonardo Uribe added a comment - I checked the code and I finally found the problem. Since 1.1, myfaces DataModel classes assume rowCount is always defined. Recently, in MYFACES-3270 , I found on the spec that rowCount can be -1, but that only means the model doesn't know how many rows are. ResultSetDataModel returns in getRowCount() by default -1. In MyFaces 1.1.3, a change was done in h:dataTable renderer to include "newspaper" mode in tomahawk. For such mode, get the rowCount is critical, because otherwise there is no way to calculate the newspaper rows and newspaper columns. The solution is add some code to iterate when getRowCount() returns -1. This issue will be fixed on 1.1.x, 1.2.x, 2.0.x and 2.1.x branches.
          Hide
          Leonardo Uribe added a comment -

          Thanks to Sagi Kovaliov for the example, it helps a lot solving this issue quickly.

          Show
          Leonardo Uribe added a comment - Thanks to Sagi Kovaliov for the example, it helps a lot solving this issue quickly.
          Hide
          Sagi Kovaliov added a comment -

          Thank you Leonardo, is there any workaround I can implement in my code in order to get DataTable with data ?

          Thanks

          Sagi

          Show
          Sagi Kovaliov added a comment - Thank you Leonardo, is there any workaround I can implement in my code in order to get DataTable with data ? Thanks Sagi

            People

            • Assignee:
              Leonardo Uribe
              Reporter:
              Sagi Kovaliov
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development