You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bill Pfeiffer <ws...@tampabay.rr.com> on 2001/05/11 21:07:57 UTC
Determining odd-even table rows
I'm trying to figure out how to do a green-bar effect (different backround
colors for every other row of a table) with struts/jsp. I am using a
tagified javax.sql.Rowset. I can iterate through the rowset via my tags
(reworked jakarta DBTags). The problem, more of a mental block, is how do I
alternate the backround colors of the html rows I am writing WITHOUT
resorting to scriptlets. I have just added a tag to get the current row, so
I have that returing, but what do I do with it?
The logic tags in struts deal only with comparisons to constants. I need to
do some math to determine whether the current row is odd/even so I can set
the backround.
Is it easier than this and I'm missing it?
My goal here is not to do any scriplets. I'm putting together a set of tags
to help our web guy build pages using only tags.
Thanks for any help,
Bill Pfeiffer
Re: Determining odd-even table rows
Posted by Ted Husted <hu...@apache.org>.
Many people like the pager tag at jsptags.com.
< http://jsptags.com/tags/navigation/pager/ >
For more on alternating colors, see
<
http://jakarta.apache.org:8080/jyve-faq/Turbine/screen/DisplayQuestionAnswer/action/SetAll/project_id/2/faq_id/36/topic_id/207/question_id/821
>
though most of these answers resort to scriptlets.
Bill Pfeiffer wrote:
> My goal here is not to do any scriplets. I'm putting together a set of tags
> to help our web guy build pages using only tags.
Re: Determining odd-even table rows
Posted by Bill Pfeiffer <ws...@tampabay.rr.com>.
Ted,
I put the jarred up copy of my RowSet tags with source on my web site
(http://home1.gte.net/pfeiffer/Download.html). This version is just as I
mentioned before: a reworking of the ResultSet tags from the taglibs Jakarta
project.
Feel free to take what you like from this, but remember it is not geared
toward general distribution (licensing and formatting certainly are not up
to snuff).
I think there is a fit for this somewhere in the DBTags portion of the
taglibs project. The only DBTags ResultSet tag that really makes a
distinction about the source of the data is the ResultSet tag itself. This
should be easily modified to accomodate a RowSet derived from an external
source.
The synching of a struts form elements with a given rowset opens a lot of
questions for me.
- How do I map from a html struts form to multiple row RowSet?
- Should struts provide functionality for scrollable RowSet?
- What level of functionality supported by a RowSet can/should I provide in
mapping from a struts form to a RowSet (Insert, Delete, Modify, None of the
above)?
- Where does the line of responsibility for such logic get drawn between a
tag and an action class?
I'm sure there are a hundred more question like this, but its getting past
my bedtime.
Let me know what you think,
Bill Pfeiffer
----- Original Message -----
From: "Ted Husted" <hu...@apache.org>
To: <st...@jakarta.apache.org>
Sent: Sunday, May 13, 2001 2:39 PM
Subject: Re: Determining odd-even table rows
> That sounds cool, Bill.
>
> I'm making extensive use of RowSets now myself. Right now, I pump the
> RowSet into a bean or collection of beans and pass that to iterate or a
> form. I use a custom constructor for the bean with a parameter for each
> property so that I can pass everything once.
>
> On the 1.1 list now is enhancing iterate to recognize RowSets (and XML)
> so that these can be used in addition to a collection of beans.
>
> In working with RowSets, I keep coming back to the idea that in practice
> my RowSets and my ActionForm beans share same properties. RowSets can
> also set and get any column as a String, which is an essential part of
> being an ActionForm bean. RowSets also have many built-in data
> conversion methods that most applications need. So it just seems to me
> that if we are going to extend iterate to support RowSets, why not
> extend the other custom tags too? Why not an ActionRowSet with a reset
> and validate method for the action to call?
>
> I haven't researched the code yet, but off-hand the real trick would
> seem to be creating a RowSet from scratch, so that it could be populated
> outside of the JDBC command. But since Cached RowSets allow you to
> create and populate columns, we should be able to do that too.
>
> The Sun documentation mentions that RowSets are suppose to be JavaBeans,
> and I did try to feed them to iterate, but it doesn't seem to work.
>
> If you would like to send me the source you have so far, perhaps we can
> work on refactoring it together.
>
> Bill Pfeiffer wrote:
> >
> > Ted,
> >
> > So far, my work with setting up a RowSet rather than a ResultSet
consists of
> > the following:
> >
> > 1. Reworking the DBTags ResultSetTag (and all nested tags) to use
> > javax.sql.RowSet instead of ResultSet.
> >
> > 2. Reworking the ResultSetTag to grab a RowSet object out of a given
context
> > (page, request, session, application), instead of relying on a parent
tag
> > generated Statement. The idea here is that some other code (servlet,
struts
> > action, etc) will create the result set and shove it into the scoped
> > attribute.
> >
> > This doesn't really constitute much original work on my part. But it
does
> > allow me to create the RowSet in the EJB layer. I have created a
session
> > bean that will take a sql string, create the RowSet, and pass it back.
> >
> > I can pass this along, however, I think it would be in the best interest
of
> > the taglibs community to somehow integrate what I have with the current
> > result set implementation. In all actuality, I don't HAVE to use a
RowSet.
> > Since RowSet implements ResultSet, I could have just modified the
ResultSet
> > tag to somehow 'know' when to use a parent Statement or get an existing
> > result set from the pageContext (which is what I do now).
> >
> > As far as struts is concerned, I would be curious to know how you would
see
> > RowSet tags integrating with it. Is the idea that you would map or bind
a
> > struts form field to a RowSet column?
> >
> > I'll get started by joining the taglibs-dev mailing list.
> >
> > I can send you my source set for the RowSet stuff I've done, but it is
far
> > from ready for prime time.
> >
> > Let me know,
> >
> > Bill
Re: Determining odd-even table rows
Posted by Ted Husted <hu...@apache.org>.
That sounds cool, Bill.
I'm making extensive use of RowSets now myself. Right now, I pump the
RowSet into a bean or collection of beans and pass that to iterate or a
form. I use a custom constructor for the bean with a parameter for each
property so that I can pass everything once.
On the 1.1 list now is enhancing iterate to recognize RowSets (and XML)
so that these can be used in addition to a collection of beans.
In working with RowSets, I keep coming back to the idea that in practice
my RowSets and my ActionForm beans share same properties. RowSets can
also set and get any column as a String, which is an essential part of
being an ActionForm bean. RowSets also have many built-in data
conversion methods that most applications need. So it just seems to me
that if we are going to extend iterate to support RowSets, why not
extend the other custom tags too? Why not an ActionRowSet with a reset
and validate method for the action to call?
I haven't researched the code yet, but off-hand the real trick would
seem to be creating a RowSet from scratch, so that it could be populated
outside of the JDBC command. But since Cached RowSets allow you to
create and populate columns, we should be able to do that too.
The Sun documentation mentions that RowSets are suppose to be JavaBeans,
and I did try to feed them to iterate, but it doesn't seem to work.
If you would like to send me the source you have so far, perhaps we can
work on refactoring it together.
Bill Pfeiffer wrote:
>
> Ted,
>
> So far, my work with setting up a RowSet rather than a ResultSet consists of
> the following:
>
> 1. Reworking the DBTags ResultSetTag (and all nested tags) to use
> javax.sql.RowSet instead of ResultSet.
>
> 2. Reworking the ResultSetTag to grab a RowSet object out of a given context
> (page, request, session, application), instead of relying on a parent tag
> generated Statement. The idea here is that some other code (servlet, struts
> action, etc) will create the result set and shove it into the scoped
> attribute.
>
> This doesn't really constitute much original work on my part. But it does
> allow me to create the RowSet in the EJB layer. I have created a session
> bean that will take a sql string, create the RowSet, and pass it back.
>
> I can pass this along, however, I think it would be in the best interest of
> the taglibs community to somehow integrate what I have with the current
> result set implementation. In all actuality, I don't HAVE to use a RowSet.
> Since RowSet implements ResultSet, I could have just modified the ResultSet
> tag to somehow 'know' when to use a parent Statement or get an existing
> result set from the pageContext (which is what I do now).
>
> As far as struts is concerned, I would be curious to know how you would see
> RowSet tags integrating with it. Is the idea that you would map or bind a
> struts form field to a RowSet column?
>
> I'll get started by joining the taglibs-dev mailing list.
>
> I can send you my source set for the RowSet stuff I've done, but it is far
> from ready for prime time.
>
> Let me know,
>
> Bill
Re: Determining odd-even table rows
Posted by Bill Pfeiffer <ws...@tampabay.rr.com>.
Ted,
So far, my work with setting up a RowSet rather than a ResultSet consists of
the following:
1. Reworking the DBTags ResultSetTag (and all nested tags) to use
javax.sql.RowSet instead of ResultSet.
2. Reworking the ResultSetTag to grab a RowSet object out of a given context
(page, request, session, application), instead of relying on a parent tag
generated Statement. The idea here is that some other code (servlet, struts
action, etc) will create the result set and shove it into the scoped
attribute.
This doesn't really constitute much original work on my part. But it does
allow me to create the RowSet in the EJB layer. I have created a session
bean that will take a sql string, create the RowSet, and pass it back.
I can pass this along, however, I think it would be in the best interest of
the taglibs community to somehow integrate what I have with the current
result set implementation. In all actuality, I don't HAVE to use a RowSet.
Since RowSet implements ResultSet, I could have just modified the ResultSet
tag to somehow 'know' when to use a parent Statement or get an existing
result set from the pageContext (which is what I do now).
As far as struts is concerned, I would be curious to know how you would see
RowSet tags integrating with it. Is the idea that you would map or bind a
struts form field to a RowSet column?
I'll get started by joining the taglibs-dev mailing list.
I can send you my source set for the RowSet stuff I've done, but it is far
from ready for prime time.
Let me know,
Bill
----- Original Message -----
From: "Ted Husted" <hu...@apache.org>
To: <st...@jakarta.apache.org>
Sent: Sunday, May 13, 2001 12:00 PM
Subject: Re: Determining odd-even table rows
> I'd be extremely interested in a tag that rolls through a RowSet.
>
> The Jakarta DBTags work directly with result sets. I'm not aware of any
> support for RowSets there. So, you may want to start by contributing it
> there, perhaps as an addition to the existing DBTags library.
>
> Meanwhile, providing direct support in Struts for RowSets would be a
> Very Good Thing. If we can enhance the HTML tags to work as easily with
> RowSets as they do with ActionForm beans, we could eliminate a layer of
> classes in many cases.
>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Custom Software ~ Technical Services.
> -- Tel 716 737-3463.
> -- http://www.husted.com/about/struts/
Re: Determining odd-even table rows
Posted by Ted Husted <hu...@apache.org>.
I'd be extremely interested in a tag that rolls through a RowSet.
The Jakarta DBTags work directly with result sets. I'm not aware of any
support for RowSets there. So, you may want to start by contributing it
there, perhaps as an addition to the existing DBTags library.
Meanwhile, providing direct support in Struts for RowSets would be a
Very Good Thing. If we can enhance the HTML tags to work as easily with
RowSets as they do with ActionForm beans, we could eliminate a layer of
classes in many cases.
-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/
Re: Determining odd-even table rows
Posted by Bill Pfeiffer <ws...@tampabay.rr.com>.
Niall,
Your response got me headed in the right decision. I have already written
my own iteration scheme that rolls through a returned RowSet. As such, I
went ahead and wrote a tag that would return a class attribute the will
rotate through class values. Example:
<tr <afrs:RotateClass id="caseTableClasses" classes="dataViewOdd
dataViewEven"/> >
where
id attribute: uniquely identifies this set of class values to rotate through
for this page (scoped within the pageContext)
classes attribute: provides a space delimited list of class values to rotate
through. Note that even though my examples shows only two class items,
there could be any number.
The example above would yeild:
<tr class="dataViewOdd "> on the first time through, and
<tr class="dataViewEven "> on the second time through
The tag is not dependant on any iteration sheme other than it expects to be
used within the scope of some type of iteration. The tag also assumes that
the classes identified in the 'classes' attribute have been set up in a
style sheet or style tag.
If anyone thinks this would be generically useful, I'd be glad to contribute
it to the taglibs project. If it appears to be redundant effort, I won't
bother.
Thanks for the response,
Bill Pfeiffer
----- Original Message -----
From: "Niall Pemberton" <ni...@btInternet.com>
To: <st...@jakarta.apache.org>
Sent: Friday, May 11, 2001 6:02 PM
Subject: RE: Determining odd-even table rows
> I have a RowTag that does this, it generates <tr> elements and you can
> specify either oddColor/evenColor attributes to generate bgcolor=
attributes
> or oddStyle/evenStyle parameters to generate class= attributes for CSS.
>
> So the jsp looks like this:
>
> <table>
> <logic:iterate id=".." name=".." property="..">
> <util:row oddColor="#C0C0C0" evenColor="#FF0000">
> <td>.....</td>
> <td>.....</td>
> </util:row>
> </logic:iterate>
> </table>
>
> You can either specify both odd and even or just one of them.
>
> I'll send it if you're interested.
>
> Niall
>
>
> > -----Original Message-----
> > From: Bill Pfeiffer [mailto:wsplist1@tampabay.rr.com]
> > Sent: 11 May 2001 20:08
> > To: Struts-User
> > Subject: Determining odd-even table rows
> >
> >
> > I'm trying to figure out how to do a green-bar effect (different
backround
> > colors for every other row of a table) with struts/jsp. I am using a
> > tagified javax.sql.Rowset. I can iterate through the rowset via my tags
> > (reworked jakarta DBTags). The problem, more of a mental block,
> > is how do I
> > alternate the backround colors of the html rows I am writing WITHOUT
> > resorting to scriptlets. I have just added a tag to get the
> > current row, so
> > I have that returing, but what do I do with it?
> >
> > The logic tags in struts deal only with comparisons to constants.
> > I need to
> > do some math to determine whether the current row is odd/even so I can
set
> > the backround.
> >
> > Is it easier than this and I'm missing it?
> >
> > My goal here is not to do any scriplets. I'm putting together a
> > set of tags
> > to help our web guy build pages using only tags.
> >
> > Thanks for any help,
> >
> > Bill Pfeiffer
> >
> >
>
>
RE: Determining odd-even table rows
Posted by Niall Pemberton <ni...@btInternet.com>.
I have a RowTag that does this, it generates <tr> elements and you can
specify either oddColor/evenColor attributes to generate bgcolor= attributes
or oddStyle/evenStyle parameters to generate class= attributes for CSS.
So the jsp looks like this:
<table>
<logic:iterate id=".." name=".." property="..">
<util:row oddColor="#C0C0C0" evenColor="#FF0000">
<td>.....</td>
<td>.....</td>
</util:row>
</logic:iterate>
</table>
You can either specify both odd and even or just one of them.
I'll send it if you're interested.
Niall
> -----Original Message-----
> From: Bill Pfeiffer [mailto:wsplist1@tampabay.rr.com]
> Sent: 11 May 2001 20:08
> To: Struts-User
> Subject: Determining odd-even table rows
>
>
> I'm trying to figure out how to do a green-bar effect (different backround
> colors for every other row of a table) with struts/jsp. I am using a
> tagified javax.sql.Rowset. I can iterate through the rowset via my tags
> (reworked jakarta DBTags). The problem, more of a mental block,
> is how do I
> alternate the backround colors of the html rows I am writing WITHOUT
> resorting to scriptlets. I have just added a tag to get the
> current row, so
> I have that returing, but what do I do with it?
>
> The logic tags in struts deal only with comparisons to constants.
> I need to
> do some math to determine whether the current row is odd/even so I can set
> the backround.
>
> Is it easier than this and I'm missing it?
>
> My goal here is not to do any scriplets. I'm putting together a
> set of tags
> to help our web guy build pages using only tags.
>
> Thanks for any help,
>
> Bill Pfeiffer
>
>