You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by dh...@lexmark.com on 2001/06/14 22:34:12 UTC

Proposal to add "indexed" to tags for Grid/Matrix-type use of Struts


Hi everyone.

I have been working on adding the new functionality of the iterate tag (the
getIndex() method) to relevant tags to allow me to refer to each of them in each
row in a table ie creating indexed names such as
name="myCollection[i].myProperty"  (search mailing list for Grid or Matrix for
further ref).

I have had good success by simply adding a few lines of code to the
BaseHandlerTag.java which gets the index of the collection being iterated over
and creates indexed names, if "indexed=true" is added to the tag.  eg

      <html:text name="parameter" property="value" indexed="true"/>
   produces
     <input type="text" name="parameter[0].value" value="Mac"> etc.

This works great for the html:text, html:hidden etc that extend BaseFieldTag.
It is a simple matter to add the functionality to Button, Cancel, Checkbox etc..

Note this is somewhat different to code Jeff Trent posted, in that the index is
NOT specified, but is derived from the iterated collection directly.  It also
adds functionality to the regular Struts tags, rather than creating another set
of "Indexedxxx" tags (though, I made reference to Jeff's code, along with Martin
Cooper's!)

I would like to propose these simple change are made to the Struts tag (though
probably not for 1.0!!).  It seems to me that are pretty clean, and would make a
big difference to the above type of usage.  If anyone would like to view this
code, please let me know (although it will be next week now, as I am off
tomorrow - yippee!!).

Cheers,

Dave