I think Struts does a good job dealing with the whole MVC separation
issues... Embedding SQL into yet-another-custom tag seems to (IMHO)
violate a number of the principles Struts is trying to uphold.

Truth-be-told, I haven't been a real JSP/custom tag fan from the start
(aren't there enough languages to learn alrady? *:^) after spending
countless hours sifting through bugs in other folkk's ASP pages and
ColdFusion pages, but the whole Struts framework "feels" right and does a
great job letting you have a *manageable*, *flexible* and *structured*
"view" while doing most of the "controller" work for you, leaving only the
icky "model" details to really work out. The fact that it works with Java
is icing on the cake *:^)

Tossing SQL directly into the "view" re-introduces the potential for
unmanageabe web code (again, IMHO).

It would be great to hear from those who have dealt with this more in the
Java world, tho, on their feelings of SQL-JSP-MVC.

As an aside, there is a good start on SQL taglibs - the DBTags tag library
- in the jakarta-taglibs project -
http://jakarta.apache.org/taglibs/doc/dbtags-doc/intro.html in case an
individual wanted to see how to integrate this into Struts w/o
re-inventing the wheel. An excerpt from their example page yields the
following (which looks similar to what you were trying to do):

<%-- print the rows in an HTML table --%>
<table>
<sql:statement id="stmt1" conn="conn1">
 
  <sql:query>
    select id, name, description from test_books
    order by 1
  </sql:query>
  
  <%-- loop through the rows of your query --%>
  <sql:resultSet id="rset2">
    <tr>
      <td><sql:getColumn position="1"/></td>
      <td><sql:getColumn position="2"/></td>
      <td><sql:getColumn position="3"/>
          <%-- print out a comment if the book has no description --%>
          <sql:wasNull>[no description]</sql:wasNull></td>
    </tr>
  </sql:resultSet>
  
</sql:statement>
</table>


boB Rudis
[EMAIL PROTECTED]
http://www.rudis.net/

+----------------+
| "Mind the gap" |
+----------------+

On Mon, 7 May 2001, Mindaugas Idzelis wrote:

> I just thought of another option: If resultsets are tied to a connection and
> a statement, then specify the sql query within the iterator:
> 
> Hypothetical taglibs:
> <sql:query id="myQuery">
>               SELECT col1, col2
>               FROM table
>               WHERE id > 1
>               <!-- even use <bean:write> in here to dynamically make queries -->
> </sql:query>
> <logic:iterate id="row" query="myQuery">
>       <bean:write name="row" property="col1"/>
>       <bean:write name="row" property="col2"/>
>       <br>
> </logic:iterate>
> 
> Where sql:query would only be evauluated once per iteration. Would this be
> possible to create? I have never authored a taglib, so any feedback from
> taglib veterans is greatly appreciated. I think this would be a great
> addition to the taglibs framework.
> 
> --min
> 
> -----Original Message-----
> From: Jonathan Asbell [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, May 06, 2001 11:47 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Suggestion/Idea for <iterate> tag: Iterate ResultSets
> 
> 
> Result sets ARE tied to the connection in a way.  Some DB drivers throw
> exceptions when you try to manipulate data while you still have a pointer to
> rows.  At work we were trying to manipulate a stream which was pointing to
> an output parameter in a stored proc while the connection was open.  The
> result was that we had to convert the stream into another object (String in
> our case) and close the connection just to manipulate the data.
> 
> ----- Original Message -----
> From: "Mindaugas Idzelis" <[EMAIL PROTECTED]>
> To: "struts" <[EMAIL PROTECTED]>
> Sent: Sunday, May 06, 2001 9:33 PM
> Subject: Suggestion/Idea for <iterate> tag: Iterate ResultSets
> 
> 
> > I just thought up of an excellent idea (although, I wasn't the only one).
> > Use the iterate tag to iterate over the rows of a resultset. The column
> meta
> > data could be exposed as beans named as the column name. A <bean:write>
> > operation would display the data in the column.
> >
> > I did a search about this topic in the mailing list archive, and I found
> > this message:
> >
> > http://marc.theaimsgroup.com/?l=struts-user&m=98269295229785&w=2
> >
> > It talk about ResultSets being tied to connections. This is not the case.
> > ResultSets are tied to the statements that produced them, and as far as I
> > can tell, statements are not closed when the connection is closed.
> >
> > Other than that, It should be easy to change the iterate tag to support
> > resultsets. If anyone is interested in helping me extend or develop a tag
> > for this purpose, please message me.
> >
> > --min
> >
> 
> 

Reply via email to