You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Guido <gu...@ribera.tel.uva.es> on 2003/03/14 16:24:08 UTC

Data driven struts application

95% of my struts web apps follow this flow:

1. User selection in a JSP
2. Action class performs a SQL query
3. Return ActionForward to a new JSP that renders the query ResultSet

What is the best practice to show SQL query results (ResultSet) to the 
user? (I mean how communication between view and controller should be 
when I do extensive use of ResulSets)

Actually, we are including the ResultSet in the request :(, and 
processing it in the JSP (using a scriptlet). But I dont like this 
aproach very much, so I wonder if it would be better to:

+ solution 1. Use a RowSetDynaClass instead of the ResultSet.
+ solution 2. Use a JavaBean with getters and setters (maybe as database 
column names) and include a JavaBean collection in the request as a 
Value Object (?)
+ solution 3. I don't know... :(

Thank you very much,
Guido.

PD. Is it better to use a collection of JavaBeans or use just one 
JavaBean whose properties return a collection??



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


Re: Data driven struts application

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 14 Mar 2003, Robert McIntosh wrote:

> Date: Fri, 14 Mar 2003 09:38:50 -0600
> From: Robert McIntosh <ro...@bull-enterprises.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Re: Data driven struts application
>
> Using a ResultSet directly is generally seen as bad practice.
>
> At a minimum you should probably use the ResultSetDynaClass then next in
> line would be a RowSetDynaClass, then JavaBeans. As for the JavaBean
> properties question, it would be easier to return a Collection of
> JavaBeans where each bean represented each row in the resultset.
>

Note that using ResultSetDynaClass doesn't get you out of leaving the
underlying ResultSet open (and the connection allocated from your
connection pool), so it is still not the best choice for making data
available to the view tier.  It's primary value is exposing ResultSet data
as DynaBeans for processing inside the business tier.  For maximum
efficiency, no data copying is done -- it essentially synthesizes a
DynaBean for the current row (have a look at the sources if you want to
see the world's strangest "Iterator" implementation :-).

RowSetDynaClass, on the other hand, is quite useful for making data
available to the view tier.  It makes a copy of the data, so the
underlying result set can be immediately closed, and the connection
returned to the connection pool.  And, because it again exposes DynaBeans,
all the standard Struts tags can deal with it just like a collection of
standard JavaBeans.  The only downside is that the copying can be
computationaly and/or memory-wise expensive, so be sure you don't try
things like performing a million row query and then trying to make a
RowSetDynaClass out of it.

> ~Robert

Craig McClanahan

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


Re: Data driven struts application

Posted by Robert McIntosh <ro...@bull-enterprises.com>.
Using a ResultSet directly is generally seen as bad practice.

At a minimum you should probably use the ResultSetDynaClass then next in 
line would be a RowSetDynaClass, then JavaBeans. As for the JavaBean 
properties question, it would be easier to return a Collection of 
JavaBeans where each bean represented each row in the resultset.

~Robert

Guido wrote:

> 95% of my struts web apps follow this flow:
>
> 1. User selection in a JSP
> 2. Action class performs a SQL query
> 3. Return ActionForward to a new JSP that renders the query ResultSet
>
> What is the best practice to show SQL query results (ResultSet) to the 
> user? (I mean how communication between view and controller should be 
> when I do extensive use of ResulSets)
>
> Actually, we are including the ResultSet in the request :(, and 
> processing it in the JSP (using a scriptlet). But I dont like this 
> aproach very much, so I wonder if it would be better to:
>
> + solution 1. Use a RowSetDynaClass instead of the ResultSet.
> + solution 2. Use a JavaBean with getters and setters (maybe as 
> database column names) and include a JavaBean collection in the 
> request as a Value Object (?)
> + solution 3. I don't know... :(
>
> Thank you very much,
> Guido.
>
> PD. Is it better to use a collection of JavaBeans or use just one 
> JavaBean whose properties return a collection??
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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