You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jeff Trent <jt...@structsoft.com> on 2001/06/09 09:40:09 UTC

Grid / Matrix Controls Made Easy (src included)

Attached, you will find a couple of new tags I wrote to extend the HTML tag library that comes with struts that will allow you to write grid-style JSP code that looks like the following:

        <% int i = 0; %>
        <logic:iterate id="item" name="inventoryForm" property="items">
        <tr>
            <td></td>
            <td class="smallFont"><html:gridtext name="item" property="name" index="<%= i %>" maxlength="nameMaxSize" size="30"/></td>
            <td class="smallFont"><html:gridtext name="item" property="description" index="<%= i %>" maxlength="descriptionMaxSize" size="50"/></td>
            <td class="smallFont" align="center" valign="center"><html:gridcheckbox name="item" property="containerFlag" index="<%= i %>" value="Y"/></td>
        </tr>
        <% i++; %>
        </logic:iterate>


Here is a synopsis of what I did:
    (1) added two tags called "gridtext" and "gridcheckbox" that are based on html:text and html:checkbox respectfully.  Note: All of the others (ie. hidden, radio, select, etc.) need to eventually be handled in a similar fashion but this is all I needed for right now.  I'll keep you posted on the rest as I create new gridXXX tags.  Note 2: this code has in no way been endorsed by Apache / Struts.  Therefore, buyer beware!  This code could easily break in future releases to struts.
    
    (2) gridtext can now optionally take an index field.  If no index is given, the behavior of gridtext degenerates to your vanilla html:text tag.  If index is specified, it will use the correct semantics for referring to your iterated item in the collection.

    (3) gridtext can now optionally take a bean property name in place of a literal value for the maxlength.  I felt this is more convenient than the alternative (using scriptlet).  To use this style, make sure your underlying bean object (in the above case its the "item" bean), has a member called getNameMaxSize() which returns a string.  Note: "size" still requires a literal, the bean will not be consulted if you use a property name instead.

    (4) gridcheckbox.  Well, let me tell you - a lot was changed in gridcheckbox!  I began by copying the code for checkbox tag over to gridcheckbox.  I changed all private declarations over to protected, removed the 'final' on the class declaration, and fixed a few bugs along the way.  Bugs included: (a) wrong target package, (b) used new RequestUtil to get bean value (not really a bug), (c) handle the value parameter correctly (in the 3.2.1 release, the value clause was being confused with the data coming back in the form post.  gridcheckbox will really take your user-defined value and put it in the "value" attribute.  Also, "checked" logic will use your "value" attribute and compare to datavalue posted from the form.  If value is not specified, the default value will be "true").

    (5) gridcheckbox can now optionally take an index field just like gridtext...

Also, note: this has not been qa'ed properly.  I wrote the code in under an hour and wham, here you go. If there are bugs you find in the indexing logic, feel free to let me know.

A few words on checkboxes:
    As many of you know, if a form is posted and no checkboxes are checked, html (and therefore struts) will not fire the setter(s) for those checkbox properties.  To solve this problem, you should depend on your reset() method on your form to clear out all of the checkbox values each time reset() is called.

To incorporate this code, do the following:
    (1) make a backup of your struts-html.tld
    (2) overwrite your project-level struts-html.tld with the one attached.
    (3) put GridTextTag.java & GridCheckboxTag.java in your project.
    (4) send me email to let me know how you fared with them ;^)  I'd like to hear from you.

cheers,
jeff



Re: Grid / Matrix Controls Made Easy (src included)

Posted by Jeff Trent <jt...@structsoft.com>.
Here it is.

----- Original Message ----- 
From: "Tom Miller" <tm...@kdsi.net>
To: <st...@jakarta.apache.org>; <jt...@structsoft.com>
Sent: Sunday, June 10, 2001 8:50 AM
Subject: Re: Grid / Matrix Controls Made Easy (src included)


> Jeff
> 
> I'm very interested in trying your code, but only the TLD was attached.
> Would you please repost?
> 
> Thanks
> Tom Miller
> 
> Jeff Trent wrote:
> 
> > Attached, you will find a couple of new tags I wrote to extend the
> > HTML tag library that comes with struts that will allow you to write
> > grid-style JSP code that looks like the following:         <% int i =
> > 0; %>
> >         <logic:iterate id="item" name="inventoryForm"
> > property="items">
> >         <tr>
> >             <td></td>
> >             <td class="smallFont"><html:gridtext name="item"
> > property="name" index="<%= i %>" maxlength="nameMaxSize"
> > size="30"/></td>
> >             <td class="smallFont"><html:gridtext name="item"
> > property="description" index="<%= i %>" maxlength="descriptionMaxSize"
> > size="50"/></td>
> >             <td class="smallFont" align="center"
> > valign="center"><html:gridcheckbox name="item"
> > property="containerFlag" index="<%= i %>" value="Y"/></td>
> >         </tr>
> >         <% i++; %>
> >         </logic:iterate> Here is a synopsis of what I did:    (1)
> > added two tags called "gridtext" and "gridcheckbox" that are based on
> > html:text and html:checkbox respectfully.  Note: All of the others
> > (ie. hidden, radio, select, etc.) need to eventually be handled in a
> > similar fashion but this is all I needed for right now.  I'll keep you
> > posted on the rest as I create new gridXXX tags.  Note 2: this code
> > has in no way been endorsed by Apache / Struts.  Therefore, buyer
> > beware!  This code could easily break in future releases to
> > struts.     (2) gridtext can now optionally take an index field.  If
> > no index is given, the behavior of gridtext degenerates to your
> > vanilla html:text tag.  If index is specified, it will use the correct
> > semantics for referring to your iterated item in the collection.
> > (3) gridtext can now optionally take a bean property name in place of
> > a literal value for the maxlength.  I felt this is more convenient
> > than the alternative (using scriptlet).  To use this style, make sure
> > your underlying bean object (in the above case its the "item" bean),
> > has a member called getNameMaxSize() which returns a string.  Note:
> > "size" still requires a literal, the bean will not be consulted if you
> > use a property name instead.     (4) gridcheckbox.  Well, let me tell
> > you - a lot was changed in gridcheckbox!  I began by copying the code
> > for checkbox tag over to gridcheckbox.  I changed all private
> > declarations over to protected, removed the 'final' on the class
> > declaration, and fixed a few bugs along the way.  Bugs included: (a)
> > wrong target package, (b) used new RequestUtil to get bean value (not
> > really a bug), (c) handle the value parameter correctly (in the 3.2.1
> > release, the value clause was being confused with the data coming back
> > in the form post.  gridcheckbox will really take your user-defined
> > value and put it in the "value" attribute.  Also, "checked" logic will
> > use your "value" attribute and compare to datavalue posted from the
> > form.  If value is not specified, the default value will be
> > "true").     (5) gridcheckbox can now optionally take an index field
> > just like gridtext... Also, note: this has not been qa'ed properly.  I
> > wrote the code in under an hour and wham, here you go. If there are
> > bugs you find in the indexing logic, feel free to let me know. A few
> > words on checkboxes:    As many of you know, if a form is posted and
> > no checkboxes are checked, html (and therefore struts) will not fire
> > the setter(s) for those checkbox properties.  To solve this problem,
> > you should depend on your reset() method on your form to clear out all
> > of the checkbox values each time reset() is called. To incorporate
> > this code, do the following:    (1) make a backup of your
> > struts-html.tld    (2) overwrite your project-level struts-html.tld
> > with the one attached.    (3) put GridTextTag.java &
> > GridCheckboxTag.java in your project.    (4) send me email to let me
> > know how you fared with them ;^)  I'd like to hear from
> > you. cheers,jeff
> 
> --
> Tom Miller
> Miller Associates, Inc.
> tmiller@kdsi.net
> 641.469.3535 Phone
> 413.581.6326 FAX
> 
> 

Re: Grid / Matrix Controls Made Easy (src included)

Posted by Tom Miller <tm...@kdsi.net>.
Jeff

I'm very interested in trying your code, but only the TLD was attached.
Would you please repost?

Thanks
Tom Miller

Jeff Trent wrote:

> Attached, you will find a couple of new tags I wrote to extend the
> HTML tag library that comes with struts that will allow you to write
> grid-style JSP code that looks like the following:         <% int i =
> 0; %>
>         <logic:iterate id="item" name="inventoryForm"
> property="items">
>         <tr>
>             <td></td>
>             <td class="smallFont"><html:gridtext name="item"
> property="name" index="<%= i %>" maxlength="nameMaxSize"
> size="30"/></td>
>             <td class="smallFont"><html:gridtext name="item"
> property="description" index="<%= i %>" maxlength="descriptionMaxSize"
> size="50"/></td>
>             <td class="smallFont" align="center"
> valign="center"><html:gridcheckbox name="item"
> property="containerFlag" index="<%= i %>" value="Y"/></td>
>         </tr>
>         <% i++; %>
>         </logic:iterate> Here is a synopsis of what I did:    (1)
> added two tags called "gridtext" and "gridcheckbox" that are based on
> html:text and html:checkbox respectfully.  Note: All of the others
> (ie. hidden, radio, select, etc.) need to eventually be handled in a
> similar fashion but this is all I needed for right now.  I'll keep you
> posted on the rest as I create new gridXXX tags.  Note 2: this code
> has in no way been endorsed by Apache / Struts.  Therefore, buyer
> beware!  This code could easily break in future releases to
> struts.     (2) gridtext can now optionally take an index field.  If
> no index is given, the behavior of gridtext degenerates to your
> vanilla html:text tag.  If index is specified, it will use the correct
> semantics for referring to your iterated item in the collection.
> (3) gridtext can now optionally take a bean property name in place of
> a literal value for the maxlength.  I felt this is more convenient
> than the alternative (using scriptlet).  To use this style, make sure
> your underlying bean object (in the above case its the "item" bean),
> has a member called getNameMaxSize() which returns a string.  Note:
> "size" still requires a literal, the bean will not be consulted if you
> use a property name instead.     (4) gridcheckbox.  Well, let me tell
> you - a lot was changed in gridcheckbox!  I began by copying the code
> for checkbox tag over to gridcheckbox.  I changed all private
> declarations over to protected, removed the 'final' on the class
> declaration, and fixed a few bugs along the way.  Bugs included: (a)
> wrong target package, (b) used new RequestUtil to get bean value (not
> really a bug), (c) handle the value parameter correctly (in the 3.2.1
> release, the value clause was being confused with the data coming back
> in the form post.  gridcheckbox will really take your user-defined
> value and put it in the "value" attribute.  Also, "checked" logic will
> use your "value" attribute and compare to datavalue posted from the
> form.  If value is not specified, the default value will be
> "true").     (5) gridcheckbox can now optionally take an index field
> just like gridtext... Also, note: this has not been qa'ed properly.  I
> wrote the code in under an hour and wham, here you go. If there are
> bugs you find in the indexing logic, feel free to let me know. A few
> words on checkboxes:    As many of you know, if a form is posted and
> no checkboxes are checked, html (and therefore struts) will not fire
> the setter(s) for those checkbox properties.  To solve this problem,
> you should depend on your reset() method on your form to clear out all
> of the checkbox values each time reset() is called. To incorporate
> this code, do the following:    (1) make a backup of your
> struts-html.tld    (2) overwrite your project-level struts-html.tld
> with the one attached.    (3) put GridTextTag.java &
> GridCheckboxTag.java in your project.    (4) send me email to let me
> know how you fared with them ;^)  I'd like to hear from
> you. cheers,jeff

--
Tom Miller
Miller Associates, Inc.
tmiller@kdsi.net
641.469.3535 Phone
413.581.6326 FAX



Indexed bean properties in STRUTS 1.1?

Posted by Michael Mok <mo...@hotmail.com>.
Hi

Is the sample code provided by Niall Pemberton going be to integrated into STRUTS. I have added the patch and it works quite. It may not be the best solution but it would be nice to know that STRUTS 1.1 will suppor index properties such we do not have to create an index counter prior to iterating a collection and getting the values into html:text.

Check out his code below..

http://www.mail-archive.com/struts-user@jakarta.apache.org/msg05231.html

Regards


Michael Mok
www.webappcabaret.com/teatimej

  ----- Original Message ----- 
  From: Jeff Trent 
  To: struts-dev@jakarta.apache.org ; struts-user@jakarta.apache.org 
  Sent: Saturday, June 09, 2001 3:40 PM
  Subject: Grid / Matrix Controls Made Easy (src included)


  Attached, you will find a couple of new tags I wrote to extend the HTML tag library that comes with struts that will allow you to write grid-style JSP code that looks like the following:

          <% int i = 0; %>
          <logic:iterate id="item" name="inventoryForm" property="items">
          <tr>
              <td></td>
              <td class="smallFont"><html:gridtext name="item" property="name" index="<%= i %>" maxlength="nameMaxSize" size="30"/></td>
              <td class="smallFont"><html:gridtext name="item" property="description" index="<%= i %>" maxlength="descriptionMaxSize" size="50"/></td>
              <td class="smallFont" align="center" valign="center"><html:gridcheckbox name="item" property="containerFlag" index="<%= i %>" value="Y"/></td>
          </tr>
          <% i++; %>
          </logic:iterate>


  Here is a synopsis of what I did:
      (1) added two tags called "gridtext" and "gridcheckbox" that are based on html:text and html:checkbox respectfully.  Note: All of the others (ie. hidden, radio, select, etc.) need to eventually be handled in a similar fashion but this is all I needed for right now.  I'll keep you posted on the rest as I create new gridXXX tags.  Note 2: this code has in no way been endorsed by Apache / Struts.  Therefore, buyer beware!  This code could easily break in future releases to struts.
      
      (2) gridtext can now optionally take an index field.  If no index is given, the behavior of gridtext degenerates to your vanilla html:text tag.  If index is specified, it will use the correct semantics for referring to your iterated item in the collection.

      (3) gridtext can now optionally take a bean property name in place of a literal value for the maxlength.  I felt this is more convenient than the alternative (using scriptlet).  To use this style, make sure your underlying bean object (in the above case its the "item" bean), has a member called getNameMaxSize() which returns a string.  Note: "size" still requires a literal, the bean will not be consulted if you use a property name instead.

      (4) gridcheckbox.  Well, let me tell you - a lot was changed in gridcheckbox!  I began by copying the code for checkbox tag over to gridcheckbox.  I changed all private declarations over to protected, removed the 'final' on the class declaration, and fixed a few bugs along the way.  Bugs included: (a) wrong target package, (b) used new RequestUtil to get bean value (not really a bug), (c) handle the value parameter correctly (in the 3.2.1 release, the value clause was being confused with the data coming back in the form post.  gridcheckbox will really take your user-defined value and put it in the "value" attribute.  Also, "checked" logic will use your "value" attribute and compare to datavalue posted from the form.  If value is not specified, the default value will be "true").

      (5) gridcheckbox can now optionally take an index field just like gridtext...

  Also, note: this has not been qa'ed properly.  I wrote the code in under an hour and wham, here you go. If there are bugs you find in the indexing logic, feel free to let me know.

  A few words on checkboxes:
      As many of you know, if a form is posted and no checkboxes are checked, html (and therefore struts) will not fire the setter(s) for those checkbox properties.  To solve this problem, you should depend on your reset() method on your form to clear out all of the checkbox values each time reset() is called.

  To incorporate this code, do the following:
      (1) make a backup of your struts-html.tld
      (2) overwrite your project-level struts-html.tld with the one attached.
      (3) put GridTextTag.java & GridCheckboxTag.java in your project.
      (4) send me email to let me know how you fared with them ;^)  I'd like to hear from you.

  cheers,
  jeff