jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hor...@apache.org
Subject cvs commit: jakarta-taglibs/standard/examples/web/sql QueryIterate.jsp Update.jsp
Date Fri, 12 Apr 2002 23:18:51 GMT
horwat      02/04/12 16:18:51

  Modified:    standard/src/javax/servlet/jsp/jstl/sql Result.java
                        ResultImpl.java
               standard/examples/web/sql QueryIterate.jsp Update.jsp
  Log:
  Add Result.getColumnNames() method to retrieve the names of the columns in the result.
  
  Revision  Changes    Path
  1.7       +12 -2     jakarta-taglibs/standard/src/javax/servlet/jsp/jstl/sql/Result.java
  
  Index: Result.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/javax/servlet/jsp/jstl/sql/Result.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Result.java	10 Apr 2002 00:43:38 -0000	1.6
  +++ Result.java	12 Apr 2002 23:18:51 -0000	1.7
  @@ -77,18 +77,28 @@
   public interface Result {
   
       /**
  -     * Returns an array of Map objects. 
  +     * Returns an array of Map objects. Column name is used as the key
  +     * for the column value.
        *
        * @return the result rows as an array of <code>Map</code> objects
        */
       public Map[] getRows();
   
       /**
  -     * Returns an array of Objects[]
  +     * Returns an array of Objects[]. The first index
  +     * designates the Row, the second the Column. The array
  +     * stores the value at the specified row and column.
        *
        * @return the result rows as an array of <code>Object[]</code> objects
        */
       public Object[][] getRowsByIndex();
  +
  +    /**
  +     * Returns an array of column names.
  +     *
  +     * @return the column names as an array of <code>String</code> objects
  +     */
  +    public String[] getColumnNames();
   
       /**
        * Returns the number of rows in the cached ResultSet
  
  
  
  1.5       +18 -1     jakarta-taglibs/standard/src/javax/servlet/jsp/jstl/sql/ResultImpl.java
  
  Index: ResultImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/javax/servlet/jsp/jstl/sql/ResultImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ResultImpl.java	10 Apr 2002 00:43:38 -0000	1.4
  +++ ResultImpl.java	12 Apr 2002 23:18:51 -0000	1.5
  @@ -71,6 +71,7 @@
   public class ResultImpl implements Result {
       private List rowMap;
       private List rowByIndex;
  +    private String[] columnNames;
       private boolean isLimited;
   
       /**
  @@ -91,6 +92,8 @@
   	int noOfColumns = rsmd.getColumnCount();
           int beginRow = 0;
   
  +        columnNames = new String[noOfColumns];
  +
           /*
            * Shift maximum rows depending on starting point
            */
  @@ -111,8 +114,11 @@
   		            value = null;
   		        }
                           // 0-based indexing to be consistent w/JSTL 
  +                        if (columnNames[i-1] == null) {
  +                            columnNames[i-1] = rsmd.getColumnName(i);
  +                        }
                           columns[i-1] = value;
  -                        columnMap.put(rsmd.getColumnName(i), value);
  +                        columnMap.put(columnNames[i-1], value);
   	            }
                   rowMap.add(columnMap);
                   rowByIndex.add(columns);
  @@ -158,6 +164,17 @@
   
           //should just be able to return Object[][] object
           return (Object [][])rowByIndex.toArray(new Object[0][0]);
  +    }
  +
  +    /**
  +     * Returns an array of String objects. The array represents
  +     * the names of the columns arranged in the same order as in
  +     * the getRowsByIndex() method.
  +     *
  +     * @return an array of String[]
  +     */
  +    public String[] getColumnNames() {
  +        return columnNames;
       }
   
       /**
  
  
  
  1.11      +12 -17    jakarta-taglibs/standard/examples/web/sql/QueryIterate.jsp
  
  Index: QueryIterate.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/sql/QueryIterate.jsp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- QueryIterate.jsp	12 Apr 2002 22:20:08 -0000	1.10
  +++ QueryIterate.jsp	12 Apr 2002 23:18:51 -0000	1.11
  @@ -75,25 +75,20 @@
   
   <h2>Putting it all together</h2>
   
  +<%-- Easiest example showing how to populate a table --%>
   <table border="1">
  -  <c:forEach var="row" items="${deejays.rows}" varStatus="status">
  -    <%-- Get the column names for the header of the table --%>
  -    <c:choose>
  -      <c:when test="${status.count == 1}">
  -        <%-- Each row is a Map object key'd by the column name --%>
  -        <tr>
  -        <c:forEach var="metaData" items="${row}">
  -          <th><c:out value="${metaData.key}"/></th>
  -        </c:forEach>
  -        </tr>
  -      </c:when>
  -    </c:choose>
  +  <tr>
  +  <%-- Get the column names for the header of the table --%>
  +  <c:forEach var="columnName" items="${deejays.columnNames}">
  +    <th><c:out value="${columnName}"/></th>
  +  </c:forEach>
  +
  +  <%-- Get the value of each column while iterating over rows --%>
  +  <c:forEach var="row" items="${deejays.rowsByIndex}">
       <tr>
  -    <c:forEach var="column" items="${row}">
  -      <%-- Get the value of each column while iterating over rows --%>
  -      <td><c:out value="${column.value}"/></td>
  -    </c:forEach>
  -  </tr>
  +      <c:forEach var="column" items="${row}">
  +        <td><c:out value="${column}"/></td>
  +      </c:forEach>
     </c:forEach>
   </table>
   
  
  
  
  1.11      +9 -14     jakarta-taglibs/standard/examples/web/sql/Update.jsp
  
  Index: Update.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/sql/Update.jsp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Update.jsp	12 Apr 2002 22:20:08 -0000	1.10
  +++ Update.jsp	12 Apr 2002 23:18:51 -0000	1.11
  @@ -49,23 +49,17 @@
   
   </sql:transaction>
   
  -
  +<%-- An example showing how to populate a table --%>
   <table border="1">
  -  <c:forEach var="row" items="${deejays.rows}" varStatus="status">
  -    <%-- Get the column names for the header of the table --%>
  -    <c:choose>
  -      <c:when test="${status.count == 1}">
  -        <%-- Each row is a Map object key'd by the column name --%>
  -        <tr>
  -        <c:forEach var="metaData" items="${row}">
  -          <th><c:out value="${metaData.key}"/></th>
  -        </c:forEach>
  -        </tr>
  -      </c:when>
  -    </c:choose>
  +  <%-- Get the column names for the header of the table --%>
  +  <c:forEach var="columnName" items="${deejays.columnNames}">
  +    <th><c:out value="${columnName}"/></th>
  +  </c:forEach>
  +
  +  <%-- Get the value of each column while iterating over rows --%>
  +  <c:forEach var="row" items="${deejays.rows}">
       <tr>
       <c:forEach var="column" items="${row}">
  -      <%-- Get the value of each column while iterating over rows --%>
         <td><c:out value="${column.value}"/></td>
       </c:forEach>
     </tr>
  @@ -86,6 +80,7 @@
   </sql:query>
   
   
  +<%-- Yet another example showing how to populate a table --%>
   <table border="1">
     <c:forEach var="row" items="${deejays.rows}" varStatus="status">
       <%-- Get the column names for the header of the table --%>
  
  
  

--
To unsubscribe, e-mail:   <mailto:taglibs-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-dev-help@jakarta.apache.org>


Mime
View raw message