My PagedTableBean constructor looks like the following: public PagedTableBean(Connection conn, String sql, long pageNumber, long pageSize) throws PagedTableException { this.pageNumber = pageNumber; this.pageSize = pageSize; this.conn = conn; this.sql = sql;
populateBean(); } private void populateBean() throws PagedTableException { long startRow = (((pageNumber-1)*pageSize)+1); long endRow = (pageNumber*pageSize); String q = "SELECT * FROM (SELECT ROWNUM ROWNO, Q.* " + "FROM (" + sql + ") Q WHERE ROWNUM <= " + endRow + ") WHERE ROWNO >= " + startRow; try { PreparedStatement ps = conn.prepareStatement(q); ResultSet rs = ps.executeQuery(); rows = new RowSetDynaClass(rs,true); rs.close(); ps.close(); } catch(SQLException e) { throw new PagedTableException(e.getMessage()); } } public Collection getRows() { return((Collection)rows.getRows()); } It was that simple :-) And now anytime I need paging done, I simply store in my form the page number and size and pass those into my action which instantiates this request bean each time, executes the query and returns the subset of data in the request scope to the forwarded JSP. Since the action my form posts to drives what the return data would be since that is where we keep our "business logic", this will work well and apply anywhere we need this technique. I also got fancy and added a few helper methods to this PagedTableBean class to give me quick access to the current page number, whether a prev/next page exists, as well as a method called getSize() that issues a "SELECT COUNT(1) FROM (" + sql + ")" call to the database to get the number of total records. This way, I can easily show something like: [<<] 100-150 of 7532 records [>>] Let me know if you have any questions! Chris -----Original Message----- From: Rajat Pandit, Gurgaon [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 15, 2004 1:54 AM To: 'Struts Users Mailing List' Subject: RE: RowSetDynaClass Hey Chris, This seems like a pretty neat solution you have out here, could please explain this, as pagination stuff is kind of the most complicated things that I have to deal with and I see my self coding the same thing again and again over a period of time. I would really appreciate your time and effort. Thanks in adv. rajat -----Original Message----- From: CRANFORD, CHRIS [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 15, 2004 11:17 AM To: 'Struts Users Mailing List' Subject: RE: RowSetDynaClass Found the answer ;-) ... Avoid the <c:...> tags all together and stick with the standard struts tags. The following worked: <logic:iterate id="row" name="results" property="rows" scope="request" indexId="rowid"> <bean:write name="row" property="item_id" /> - <bean:write name="row" property="item_product_number"/> </logic:iterate> Now have a fast, efficient paging mechanism that permits me to pass in a database connection object, the sql query to execute, starting page # and size and it handles the rest by populating itself from the database, closing the resultset when finished and leaves the presentation part up to my JSP as above! Gotta love struts! Chris -----Original Message----- From: CRANFORD, CHRIS [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 15, 2004 12:35 AM To: '[EMAIL PROTECTED]' Subject: RowSetDynaClass I am storing a RowSetDynaClass property in my java class and I have implemented a method on my class as follows: public Collection getRows() { return((Collection)rsdc.getRows()); } In my action, I store my custom class object reference as follows: request.setAttribute("results", myResultsObj); Then in my jsp, I do the following: <bean:define scope="request" id="data" name="results" property="rows" /> <c:forEach var="row" items="${data}" varStatus="rowid"> <c:out value="${rowid.count}"/>. <c:out value="${row.item_id}" /> - <c:out value="${row.item_product_number}" /> </c:forEach> I get the following error: [ServletException in:/pages/test-body.jsp] An error occurred while evaluating custom action attribute "value" with value "${row.item_id}": Unable to find a value for "item_id" in object of class "org.apache.commons.beanutils.BasicDynaBean" using operator "." (null) Can someone tell me what I am doing wrong here and how I can do this properly to get it to work? _______________________________________________________ Chris Cranford Programmer/Developer SETECH Inc. & Companies 6302 Fairview Rd, Suite 201 Charlotte, NC 28210 Phone: (704) 362-9423, Fax: (704) 362-9409, Mobile: (704) 650-1042 Email: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]