You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matt Keveney <Ma...@nimblefish.com> on 2001/10/04 00:50:14 UTC

Using the "Indexed" attribute.

Which Struts release contains support for the "indexed" attribute (used in various HTML tags).  I discovered to my chagrin that this isn't supported in the 1.0 download.

Is there some clever way to achieve the same thing in 1.0? I can properly initialized my fields using the 'iterate' tag, but I want the parameter names to come back as "field01, field02, ..." or some-such.

TIA

-Matt

Re: Using the "Indexed" attribute.

Posted by Matt Keveney <Ma...@nimblefish.com>.
> Is there some clever way to achieve the same thing in 1.0? I can properly
initialized my fields using the
> 'iterate' tag, but I want the parameter names to come back as "field01,
field02, ..." or some-such.

All

I figured out a solution myself... though it may not conform with the
preferred Struts patterns.  Here's how I did it, for the archives:

In short, I render the HTML Input tag 'by hand' rather than using Struts
<html:checkbox> tag.  Then I add code in the action class 'submit' case
to put the parameter values in the form.

Here's the JSP:

<logic:iterate name="myForm" id="myListItem" indexId="myIdx"
property="myList" >

    ... other HTML, probably table rows & such ...

    <INPUT
       <logic:equal name="myListItem" property="enabled" value="true">
       checked
       </logic:equal>

       name=checkedListItems type=checkbox value=<bean:write name="myIdx"/>>

    ... other HTML  ...

</logic:iterate>

Notes:

    * This accesses the collection, myform.mylist.

    * The objects in that collection must have a "boolean getEnabled(int
      idx)" method.

    * Notice that I'm rendering the same parameter name
      "checkedListItems" for each checkbox, but the value is set to the
      collection index.  If the 3rd and 5th items are checked, I'll get
      a request parameter like so:

        "checkedListItems" = { "2", "4" }

    * Alternately you could leave the value set to "true" or "1" and
      construct a fancy parameter name.  Then you'd get this in the
      request.

        "checkedListItem[2]" = { "true" } "checkedListItem[4]" = {
        "true" }

      This approach seems more like the documented "indexed" attribute.


-Have fun
-Matt.



Re: Using the "Indexed" attribute.

Posted by Eric Mickelson <er...@mac.com>.
I work with a guy who has this same problem.  Maybe he can help you :-)


On Wednesday, October 3, 2001, at 03:50 PM, Matt Keveney wrote:

> Which Struts release contains support for the "indexed" attribute (used 
> in various HTML tags).  I discovered to my chagrin that this isn't 
> supported in the 1.0 download.
>  
> Is there some clever way to achieve the same thing in 1.0? I can 
> properly initialized my fields using the 'iterate' tag, but I want the 
> parameter names to come back as "field01, field02, ..." or some-such.
>  
> TIA
>  
> -Matt
>
~Eric