Cheers Dudley,

I have a solution but I am not happy with it (and I now also have the
additional problem that checkboxes only get sent back if they are set so I
can't tell which checkbox has been checked! - Another one to sort out).

Do you know if this is a design error.  Basically, the problem is this (for
those who haven't been following the thread):

- I have a number of beans held in a Vector.
- In my ActionForm I have a two getters for this vector - one returns the
vector and one returns elements of the vector - so something like this:

    public RetailerBean getRetailerBean( int index )
    {
        return (RetailerBean)retailers.elementAt( index );
    }

and

    public Vector getRetailers()
    {
        return retailers;
    }

This works fine to populate using the following type of iterate tag:

<logic:iterate id="retailer" name="retailerForm" property="retailers">
        <tr>
        <td><html:checkbox name="retailer" property="delete"/></td>
        <td><html:text name="retailer" property="name"/></td>
</a></td>-->
        </tr>
</logic:iterate>

However, it doesn't repopulate the beans when I do a submit.  This is
because the generated html is something like:

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

rather than:

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

which would allow my beans to be repopulated.

The outcome of this is that I have to create arrays for all properties of my
beans in my ActionForm and take the values from there.  This seems like
bodge-heaven and not at all object-oriented.

If the form can be populated directly from the beans then surely it should
work the other way too.

Any struts developers want to comment?

Thanks for all your help.

Cheers
Tony


-----Original Message-----
From: Dudley Butt@i-Commerce [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 1:06 PM
To: 'Tony Karas'
Subject: RE: please help...iteration question...what i Have is...GOT IT
WORKING!! LET ME kNOW IF U GOT IT WORKING


ya sorry about that the one is the actionform attribute and the other is an
attribute of my TaxPayerData[] bean.

-----Original Message-----
From: Tony Karas [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 1:46 PM
To: Dudley Butt@i-Commerce
Subject: RE: please help...iteration question...what i Have is...GOT IT
WORKING!! LET ME kNOW IF U GOT IT WORKING


OK - I see what you're doing - got a little confused with taxpayerName and
taxPayerName but worked it out.  I'm going to give it a go - see what
happens.  Will let you know....

-----Original Message-----
From: Dudley Butt@i-Commerce [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 12:29 PM
To: 'Tony Karas'
Subject: RE: please help...iteration question...what i Have is...GOT IT
WORKING!! LET ME kNOW IF U GOT IT WORKING


have a look at this multibox code i see someone also sent to u, i think that
would also work..same idea..just using a Long array........

-----Original Message-----
From: Deadman, Hal [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 09, 2001 10:30 PM
To: [EMAIL PROTECTED]
Subject: RE: Posting Collections


I think I am doing the same thing that you want to do using the
html:multibox. When the form is submitted you get an array of the ids that
are checked and then you can go delete them.

in the jsp form (where restaurant id is a key for the item being deleted):
<logic:iterate id="restaurant" name="favoriterestaurants">
...
        <html:multibox property="favoriteRestaurantRemoveList">
                <bean:write property="restaurantId" name="restaurant"/>
        </html:multibox>
...
</logic:iterate>


in the form class:
    private Long favoriteRestaurantRemoveList[] = new Long[0];

    public Long[] getFavoriteRestaurantRemoveList() {
        return (this.favoriteRestaurantRemoveList);
    }

    public void setFavoriteRestaurantRemoveList(Long
favoriteRestaurantRemoveList[]) {
        this.favoriteRestaurantRemoveList = favoriteRestaurantRemoveList;
    }

I am not sure if initializing the array to new Long[0] is necessary,
probably not.


-----Original Message-----
From: Tony Karas [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 1:13 PM
To: Dudley Butt@i-Commerce
Subject: RE: please help...iteration question...what i Have is...GOT IT
WORKING!! LET ME kNOW IF U GOT IT WORKING


Thanks very much - I'll have a look and get back to you asap.

-----Original Message-----
From: Dudley Butt@i-Commerce [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 11:49 AM
To: 'Tony Karas'
Subject: RE: please help...iteration question...what i Have is...GOT IT
WORKING!! LET ME kNOW IF U GOT IT WORKING


i may have a solution for you, let me send u my one that works with a normal
edit box and see if u can change it to work with your checkboxes. i think
the basic idea, is that once your list is displayed, u need a String[]
setter like i have.
let me know...i've attached my files  that actually work..

check it out and look at my comments





-----Original Message-----
From: Tony Karas [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 11:37 AM
To: Dudley Butt@i-Commerce
Subject: RE: please help...iteration question...what i Have is...GOT IT
WORKING!! LET ME kNOW IF U GOT IT WORKING


So you didn't need the extra method then?  I think my problem is to do with
checkboxes and the way that they are implemented.

-----Original Message-----
From: Dudley Butt@i-Commerce [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 8:50 AM
To: 'Tony Karas'
Subject: RE: please help...iteration question...what i Have is...GOT IT
WORKING!! LET ME kNOW IF U GOT IT WORKING


ActionForm....

public class TaxPayerActionForm extends FormBase {

        private ArrayList list = null;
        private String[] taxTypes = null;
        private TaxPayerData[] taxPayers = null;

public TaxPayerData[] getTaxPayers(){
        this.taxPayers = new TaxPayerData[list.size()];
        this.taxPayers = (TaxPayerData[])list.toArray(taxPayers);
          return taxPayers;
    }


JSP...
TO NOTE HERE!!! taxpayerName and email are attributes of the TaxPayerData
object

                                <logic:iterate id="taxPayerForm"
name="taxPayerForm" scope="request" property="taxPayers">
                                  <tr>
                                    <td align="center">
                                      <bean:write name="taxPayerForm"
property="taxpayerName" filter="true"/>
                                    </td>
                                    <td align="center">
                                      <bean:write name="taxPayerForm"
property="email" filter="true"/>
                                    </td>
                                    <td align="center">

                                                <html:link
page="/taxPayerEdit.do?action=Edit" ><bean:message
key="taxPayerList.edit"/></html:link>
                                        </td>

                                  </tr>
                                </logic:iterate>

-----Original Message-----
From: Tony Karas [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 09, 2001 7:02 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: please help...iteration question...what i Have is...


I'm struggling with the same problem as you are (well similar) and general
lack of information / not being able to find information.

I think you may need the following method in your ActionForm bean:

public TaxPayerData getTaxPayers( int index )
{
        return taxPayers[index];
}

as well as:

public TaxPayerData[] getTaxPayers()
{
        TaxPayerData[] taxPayers = new TaxPayerData[list.size()];
      taxPayers = (TaxPayerData[])list.toArray(taxPayers);
        return taxPayers;
}

but if anyone else can comment on this - I would also appreciate
enlightenment.

Cheers
Tony

Reply via email to