You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ca...@lombard.ca on 2001/07/25 15:00:57 UTC

Multiple checkboxes, same name...

Hi all.  Very new to this list and struts, but using it pretty successfully
for
a project at work.  Good looking framework.  Now the question:

I have a form that will list anywhere from 0-9 vehicles.
I have to allow multiple selection of vehicles.

Currently I'm using <html:select multiple="true"... type
tags, but would like to use checkboxes, so would the
following work?

Create a bean with name/value pairs for each vehicle and
do a <logic:iterate... tag and generate an <html:multibox...
for each entry (the selected vehicles are an array in a form bean).

The above sounds pretty reasonable, but I'm unsure how
to get it to work.  Specifically, how to get the proper value=
attribute in the multibox tag:

<!-- vehicles is a page-scope hashtable -->
<logic:iterate id="entry" name="vehicles">
  ** how to get the key property of 'entry' into value attrib? **
  <html:multibox property="principalOperators" value="???">
    <bean:write name="entry" property="value"/>
  </html:multibox>
</logic:iterate>

Thanks in advance,

Carmine Lucarelli



RE: Multiple checkboxes, same name...

Posted by Mark Schenk <M....@dto.tudelft.nl>.
> Hi all.  Very new to this list and struts, but using it pretty
> successfully
> for
> a project at work.  Good looking framework.  Now the question:
>
[snip]
>
> The above sounds pretty reasonable, but I'm unsure how
> to get it to work.  Specifically, how to get the proper value=
> attribute in the multibox tag:
>
> <!-- vehicles is a page-scope hashtable -->
> <logic:iterate id="entry" name="vehicles">
>   ** how to get the key property of 'entry' into value attrib? **
>   <html:multibox property="principalOperators" value="???">
>     <bean:write name="entry" property="value"/>
>   </html:multibox>
> </logic:iterate>
>

Hello Carmine,

	you've almost answered your own question: if you want the value to be
calculated during the iteration, leave the value parameter off! In this case
struts will use the body of the html:multibox tag as the value. So:

 <logic:iterate id="entry" name="vehicles">
   <html:multibox property="principalOperators">
     <bean:write name="entry" property="value"/>
   </html:multibox>
 </logic:iterate>

does what you want.

Cheers,
	Mark

----------------------------------------------------------------------------
Mark Schenk                     |	Ceci n'est pas une signature
Blackboard Project Manager      |
Delft University of Technology  |E-mail: M.M.A.Schenk@dto.tudelft.nl
Dept.: DTO                      |Phone:  +31 152785448 (85448)
Room: LB00.680                  |Fax:	 +31 152786359
----------------------------------------------------------------------------
-