struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Graham <grahamdavid1...@yahoo.com>
Subject Re: Iterating the resultset contents in the view (jsp)
Date Tue, 15 Jul 2003 03:21:38 GMT
That's certainly another option but keep in mind that it ties your app to
the web.  That may be ok if you don't plan on reusing any of the code from
the app but DynaBeans are more appropriate for building layers that are
reusable in any environment.

David

--- Kris Schneider <kris@dotech.com> wrote:
> Another datapoint: JSTL provides an interface called 
> javax.servlet.jsp.jstl.sql.Result:
> 
> public interface Result {
>    public SortedMap[] getRows();
>    public Object[][]  getRowsByIndex();
>    public String[]    getColumnNames();
>    public int         getRowCount();
>    public boolean     isLimitedByMaxRows();
> }
> 
> and a utility class javax.servlet.jsp.jstl.sql.ResultSupport:
> 
> public class ResultSupport {
>    public static Result toResult(ResultSet rs);
>    public static Result toResult(ResultSet rs, int maxRows);
> }
> 
> to accomplish something similar. The SortedMap instances returned from 
> Result.getRows are keyed by the ResultSet's column names and use the 
> Comparator String.CASE_INSENSITIVE_ORDER so that you don't have to worry
> 
> about matching the case of the column name exactly. So, depending on 
> what your preference is, you can just do:
> 
> ResultSet rs = ...;
> Result result = ResultSupport.toResult(rs);
> request.setAttribute(MyConstants.RESULT, result);
> 
> or:
> 
> ResultSet rs = ...;
> Result result = ResultSupport.toResult(rs);
> Map[] rows = result.getRows();
> request.setAttribute(MyConstants.ROWS, rows);
> 
> David Graham wrote:
> > --- Richard Hill <RHill@classmates.com> wrote:
> > 
> >>Hi,
> >>I'm working on an action that gets a resultset from a database table
> >>containing 4 columns. I need to pass that information back to the view
> >>(jsp)
> >>which will iterate over results. My question is what is the best way
> to
> >>do
> >>this. Do I create an array for each row in the resultset and insert
> each
> >>array in a collection, passing that back to the view? 
> > 
> > 
> > A fairly standard approach is to create a class that represents a row
> of
> > your ResultSet and store a List of those objects in the request for
> the
> > page to iterate over.  
> > 
> > If you don't want to create a class for each result, you should check
> out
> > the BeanUtils DynaBeans.  This little gem:
> >
>
http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/RowSetDynaClass.html
> > allows you to transer ResultSet data to DynaBeans in a trivial amount
> of
> > code.
> > 
> > David
> > 
> > 
> > 
> >>If so, how would you iterate over each array in the collection with
> the
> >>logic:iterate taglib? All of the examples only show iterations over
> >>single
> >>column lists.
> >>
> >>Any help would be appreciated.
> >>
> >>Thanks,
> >>Richard
> 
> -- 
> Kris Schneider <mailto:kris@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message