The problem is the CheckBox tag currently sets the HTML name attribute to
the property, so your JSP will produced something like this:

        <input type="checkbox" name="delete">

So all the checkbox fields will have the same name.

In order for Struts to populate your Retailer bean with the delete values
you need the generated HTML to look like this:

        <input type="checkbox" name="retailer[0].delete">
        <input type="checkbox" name="retailer[1].delete"> etc etc.

Struts would then use getRetailer(0).setDelete(boolean) to set the delete
attributes correctly.

Unfortunately there is no easy solution - many people resort to scriptlets
to generate the name properly and there are quite a few messages in the
archive about this.

I created my own versions of Struts tags and changed them to generate the
name correctly - I like that much better - no java in the view.

Niall

> -----Original Message-----
> From: Tony Karas [mailto:[EMAIL PROTECTED]]
> Sent: 09 May 2001 17:50
> To: [EMAIL PROTECTED]
> Subject: Posting Collections
>
>
> Briefly, this is what I am trying to achieve:
>
> - Retrieve a list of items from a database
> - Display each item with a corresponding checkbox
> - Display a "Delete" button - which when pressed deletes all
> checked items.
>
> Unfortunately, although I have managed to display the items correctly and
> set the checkbox value using boolean values, when I do the form
> submit - my
> ActionForm properties do not get filled in.
>
> This is the code I have:
>
> My ActionForm looks like this:
>
> public class RetailerForm extends ActionForm
> {
>     protected Vector retailer;
>
>     /*
>      * On construction, fill the form with all the retailers
>      */
>     public RetailerForm() throws SQLException
>     {
>          //here i have some code to generate my vector
>          //which is comprised of "Retailer" beans.
>     }
>
>     public Retailer getRetailer( int index )
>     {
>         return (Retailer)retailer.elementAt( index );
>     }
>
>     public Vector getRetailer()
>     {
>         return retailer;
>     }
>
>     public void setRetailer( Vector value )
>     {
>         retailer = value;
>     }
> }
>
> My "Retailer" bean has get and set elements for properties called
> "delete"
> and "name".
>
> My struts code looks like this (obviously within <html:form> tags):
>
> <logic:iterate id="retailer" name="retailerForm" property="retailer">
>       <tr>
>       <td><html:checkbox name="retailer" property="delete"/></td>
>       <td><bean:write name="retailer" property="name"/></td>
>       </tr>
> </logic:iterate>
>
> And this all works ok for displaying the data.  However, when I do the
> submit my "delete" property for each bean is not set and I have added
> debugging code to the "set" method and this is not called by struts.  I
> don't get error messages - it just doesn't happen.
>
> I know other people have had this problem, but I am struggling to find a
> solution.
>
> Can anyone help me?  Is there a better way of achieving what I am
> trying to
> achieve?  If I am doing the correct thing, what's the reason it's not
> working.
>
> All help appreciated.
>
> Cheers
> Tony
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
>

Reply via email to