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/19 17:24:04 UTC

Re: Proposal to add "indexed" to tags for Grid/Matrix-type use ofStruts


Hi everyone.

I have now finished updating several html Struts tags to produce indexed names
such as

     <input type="text" name="parameter[0].value" value="Mac">

when used within an iterate tag.  These tags involve only minor changes to the
existing tags, and to trigger them, "indexed=true" is added to the tag.

I changed BaseHandlerTag to include the "indexed" parameter with appropriate
setter & getters, and modified BaseFieldTag to change name if the indexed
parameter is specified.  This automatically provides this capability to those
tags which extend BaseFieldTag, ie FileTag, HiddenTag, PasswordTag and TextTag.

For those that do not inherit from BaseFieldTag, I changed the tag code in
ButtonTag and CheckBox tag.  I am willing to change any others that peope use
within an iterate tag and require the above indexed names.

Instructions for use:
- unpack attached zip file (this mailing list only accepts messages < 100K!!)
and copy .java files to ../org/apache/struts/taglib/html/
- rebuild struts
- add the struts-html.tld to your WEB-INF directory
- within an iterate tag, simply add "indexed=true" to the tag you wish to use.
Eg to produce the text tag

      <input type="text" name="parameter[0].value" value="Mac">

use:
      <logic:iterate id="parameter" name="ParametersForm"
property="parameterList">
      ...
            <html:text name="parameter" property="value" indexed="true"/>
      ...
      </logic:iterate>

   This presumes form bean called ParametersForm, with a getParameterList()
method which returns a collection of parameters, a getParameter(int index)
method which returns a particular parameter in the collection, and each
parameter object has a getValue() method.
- (I used the index in the name for javascript validation etc in each row)

Hope this helps.  Would really appreciate feedback from people.  Also, believe
it would be a clean enhancement to current tags - what do I need to do to
propose the change?

Dave

(See attached file: struts indexed files.ZIP)



Tom Miller <tm...@interlock.lexmark.com> on 06/15/2001 08:17:35 AM

To:   "David_Hay/Lex/Lexmark.LEXMARK"@sweeper.lex.lexmark.com
cc:    (bcc: David Hay/Lex/Lexmark)
Subject:  Re: Proposal to add "indexed" to tags for Grid/Matrix-type use
      ofStruts



Sure, I'm very interested. Please post to the list or send me a copy! The
iterate
tag has been the weakest part of struts so far. Thanks for working on it!

Tom Miller

dhay@lexmark.com wrote:

> 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

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