You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andy Kriger <ak...@greaterthanone.com> on 2002/11/13 23:40:53 UTC

indexed properties and form help needed

I know this question gets asked a lot but I've yet to see a comprehensive
coverage of how to make this work (the answers are always filling in the
blanks of a specific question). I'd be happy to start a tutorial on this
once I get my problem worked out.

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>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>