At end. > -----Original Message----- > From: Andy Kriger [mailto:akriger@;greaterthanone.com] > > I have a DynaActionForm collecting credit card info. A user > can enter up to > 3 credit cards on the form. I want to collect this info in > the text fields > and create new CreditCard objects automatically; ideally, I > would get a > CreditCard[3] once the form is submitted (optionally an > ArrayList would be > fine). I would like to use indexed properties (right now I'm > using hard > coded property names), but I cannot figure out how to set this up. > > I am getting either a 'No collection found' error or a > 'Cannot iterate over > collection' error (depending on how I mess with this). > > What follows is rough code of what I'm trying to do. > > A CreditCard object has 5 fields with get/set methods for > each: type, name, > number, expMonth, expYear. > > <!-- JSP --> > <html:form method='post' action='doSomething'> > <logic:iterate id='index' property='creditCard' > name='registrationForm' > length='3'> > <html:select property='creditCard.type' name='index' > indexed='true'> > <!-- some options --> > </html:select> > <html:text property='creditCard.name' name='index' > indexed='true'> > <html:text property='creditCard.number' name='index' > indexed='true'> > <html:text property='creditCard.expMonth' name='index' > indexed='true'> > <html:text property='creditCard.expYear' name='index' > indexed='true'> > </logic:iterate> > </html:form> > <!-- Note: I have tried html:text with property='creditCard.field' and > property='field' Neither worked --> > > <!-- struts-config.xml --> > <form-bean name='registrationForm' type='DynaValidatorForm > dynamic='true'> > <form-property name='creditCard' > type='my.package.CreditCard[]'/> > </form-bean>
Note that I haven't compiled or run any of this. I would first expect my loop to look more like this: <logic:iterate id='creditCard' property='creditCards' name='registrationForm' length='3'> <html:select name='creditCard' property='type' indexed='true'> <!-- some options --> </html:select> <html:text name='creditCard' property='name' indexed='true'/> <html:text name='creditCard' property='number' indexed='true'/> <html:text name='creditCard' property='expMonth' indexed='true'/> <html:text name='creditCard' property='expYear' indexed='true'/> </logic:iterate> I would have accessors for "name", "number", "expMonth" and "expYear" in the CreditCard class. At that point, I scratch my head, because I don't know how to represent indexed properties in DynaActionForms. With a regular ActionForm, I would have the following in my "registrationForm" bean: public CreditCard getCreditCard(int index) { return (creditCards[index]); } public void setCreditCard(int index, CreditCard creditCard) { creditCard[index] = creditCard; } public CreditCard[] getCreditCards() { return (creditCards); } -- To unsubscribe, e-mail: <mailto:struts-user-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>