Author: craigmcc
Date: Sat Feb  4 17:06:42 2006
New Revision: 374955

URL: http://svn.apache.org/viewcvs?rev=374955&view=rev
Log:
Example now works with the RI's version of UIData and ResultSetDataModel,
but not with the MyFaces version.  Need to investigate that further.

Modified:
    
struts/shale/trunk/sql-browser/src/java/org/apache/shale/examples/sqlbrowser/Query.java
    struts/shale/trunk/sql-browser/src/web/query.jsp

Modified: 
struts/shale/trunk/sql-browser/src/java/org/apache/shale/examples/sqlbrowser/Query.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/sql-browser/src/java/org/apache/shale/examples/sqlbrowser/Query.java?rev=374955&r1=374954&r2=374955&view=diff
==============================================================================
--- 
struts/shale/trunk/sql-browser/src/java/org/apache/shale/examples/sqlbrowser/Query.java
 (original)
+++ 
struts/shale/trunk/sql-browser/src/java/org/apache/shale/examples/sqlbrowser/Query.java
 Sat Feb  4 17:06:42 2006
@@ -27,6 +27,7 @@
 import java.util.List;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
 import javax.faces.component.html.HtmlDataTable;
 import javax.faces.component.html.HtmlOutputText;
 import javax.faces.context.FacesContext;
@@ -34,6 +35,7 @@
 import javax.sql.DataSource;
 import org.apache.shale.tiger.managed.Bean;
 import org.apache.shale.tiger.managed.Scope;
+import org.apache.shale.tiger.view.Destroy;
 import org.apache.shale.tiger.view.Prerender;
 import org.apache.shale.tiger.view.View;
 
@@ -48,6 +50,24 @@
     // ------------------------------------------------------ Instance 
Variables
 
 
+    /**
+     * <p>The JDBC connection we will be using.</p>
+     */
+    private Connection conn = null;
+
+
+    /**
+     * <p>The JDBC result set we will be using.</p>
+     */
+    private ResultSet rs = null;
+
+
+    /**
+     * <p>The JDBC statement we will be using.</p>
+     */
+    private PreparedStatement stmt = null;
+
+
     // ---------------------------------------------------------- JSF 
Properties
 
 
@@ -150,9 +170,6 @@
 
         // Perform the query and dynamically set up the results
         FacesContext context = FacesContext.getCurrentInstance();
-        Connection conn = null;
-        PreparedStatement stmt = null;
-        ResultSet rs = null;
         try {
 
             // Look up the appropriate data source
@@ -174,13 +191,12 @@
             ResultSetMetaData rsmd = rs.getMetaData();
             System.err.println("prerender():  There are " + 
rsmd.getColumnCount() + " columns");
 
-            // Wire up our table binding
-            System.err.println("prerender():  Wiring up our table binding");
-            resultSetDataModel = new ResultSetDataModel();
-            resultSetDataModel.setWrappedData(rs);
-            results.setValueBinding("value",
-              
context.getApplication().createValueBinding("#{query.resultSetDataModel}"));
+            // Set up the data model for our result set
+            System.err.println("prerender():  Wiring up our data model");
+            resultSetDataModel = new ResultSetDataModel(rs);
             System.err.println("prerender():  There are " + 
resultSetDataModel.getRowCount() + " rows");
+            results.setFirst(0);
+            results.setRows(10);
 
             // Dynamically create columns as needed
             System.err.println("prerender():  Dynamically creating columns");
@@ -189,6 +205,7 @@
             for (int i = 1; i <= rsmd.getColumnCount(); i++) { // SQL stuff is 
one-relative
                 System.err.println("prerender():  Adding column '" + 
rsmd.getColumnName(i) + "'");
                 UIColumn column = new UIColumn();
+                column.setId("column" + i);
                 children.add(column);
                 HtmlOutputText header = new HtmlOutputText();
                 String label = rsmd.getColumnLabel(i);
@@ -198,55 +215,110 @@
                 header.setValue(label);
                 column.setHeader(header);
                 HtmlOutputText data = new HtmlOutputText();
-                column.getChildren().add(data);
+                data.setId("data" + i);
                 data.setValueBinding("value",
-                  context.getApplication().createValueBinding("#{currentRow['" 
+ rsmd.getColumnName(i) + "']}"));
+                  context.getApplication().createValueBinding("#{current['" + 
rsmd.getColumnName(i) + "']}"));
+                System.err.println("prerender(): Value binding is " + 
data.getValueBinding("value").getExpressionString());
+                column.getChildren().add(data);
+            }
+
+            // Position to first row to ensure that we can
+            System.err.println("prerender():  Check positionability of initial 
rows");
+            for (int i = 0; i < 10; i++) {
+                resultSetDataModel.setRowIndex(i);
+                System.err.println("prerender():  Row " + i + " exists? " + 
resultSetDataModel.isRowAvailable());
+                if (!resultSetDataModel.isRowAvailable()) {
+                    break;
+                }
+                System.err.println("prerender(): Row " + i + " data: " + 
resultSetDataModel.getRowData());
             }
 
-        } catch (SQLException e) {
+            // Set the completed flag to indicate that we should display the 
results
+            System.err.println("prerender():  Marking request as completed");
+            completed = true;
+
+        } catch (Exception e) {
 
+            System.err.println("prerender():  Encountered Exception");
+            e.printStackTrace(System.err);
             context.addMessage
               (null, new FacesMessage("Exception executing this query: " + e));
             while (e != null) {
                 context.getExternalContext().
                   log("Exception executing this query", e);
-                e = e.getNextException();
+                if (e instanceof SQLException) {
+                    e = ((SQLException) e).getNextException();
+                } else {
+                    e = null;
+                }
             }
             setCompleted(false);
 
-        } finally {
+        }
+
+    }
 
-            // Close the result set (if any) that we opened
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException e) {
-                    ;
-                }
-            }
 
-            // Close the statement (if any) that we opened
-            if (stmt != null) {
-                try {
-                    stmt.close();
-                } catch (SQLException e) {
-                    ;
-                }
+    /**
+     * <p>Clean up after rendering is complete, and close the connection
+     * (which returns it to the connection pool).</p>
+     */
+    @Destroy
+    public void destroy() {
+
+        System.err.println("destroy(): Clean up after rendering completed");
+        System.err.println("destroy(): There were " + 
resultSetDataModel.getRowCount() + " rows");
+
+        // Close the result set (if any) that we opened
+        if (rs != null) {
+            try {
+                System.err.println("destroy(): Closing result set");
+                rs.close();
+            } catch (SQLException e) {
+                System.err.println("destroy(): Exception closing result set");
+                e.printStackTrace(System.err);
             }
+        }
 
-            // Close the connection (if any) that we opened
-            if (conn != null) {
-                try {
-                    conn.close();
-                } catch (SQLException e) {
-                    ;
-                }
+        // Close the statement (if any) that we opened
+        if (stmt != null) {
+            try {
+                System.err.println("destroy(): Closing statement");
+                stmt.close();
+            } catch (SQLException e) {
+                System.err.println("destroy(): Exception closing statement");
+                e.printStackTrace(System.err);
             }
+        }
 
+        // Close the connection (if any) that we opened
+        if (conn != null) {
+            try {
+                System.err.println("destroy(): Closing connection");
+                conn.close();
+            } catch (SQLException e) {
+                System.err.println("destroy(): Exception closing connection");
+                e.printStackTrace(System.err);
+            }
         }
 
-        // Set the completed flag to indicate that we should display the 
results
-        completed = true;
+        System.err.println("destroy(): Walk component tree for the table");
+        walk(FacesContext.getCurrentInstance(), results, 0);
+        System.err.println("destroy(): All done");
+
+    }
+
+
+    private void walk(FacesContext context, UIComponent component, int indent) 
{
+
+        for (int i = 0; i < indent; i++) {
+            System.err.print(" ");
+        }
+        System.err.println("clientId=" + component.getClientId(context) + ", 
type=" + component.getClass());
+        Iterator kids = component.getChildren().iterator();
+        while (kids.hasNext()) {
+            walk(context, (UIComponent) kids.next(), indent + 2);
+        }
 
     }
 

Modified: struts/shale/trunk/sql-browser/src/web/query.jsp
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/sql-browser/src/web/query.jsp?rev=374955&r1=374954&r2=374955&view=diff
==============================================================================
--- struts/shale/trunk/sql-browser/src/web/query.jsp (original)
+++ struts/shale/trunk/sql-browser/src/web/query.jsp Sat Feb  4 17:06:42 2006
@@ -77,7 +77,8 @@
       <h:dataTable                   id="results"
                                 binding="#{query.results}"
                                rendered="#{query.completed}"
-                                    var="currentRow"/>
+                                  value="#{query.resultSetDataModel}"
+                                    var="current"/>
 
     </h:panelGrid>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to