All –
New to struts2 here.. I’ve been reading some tutorials, and even picked up a book so I understand some, but please forgive me if I use the wrong terms.
I’m looking for an example or an explanation on how to create a dynamic list of text fields based on a collection, have the user enter some input and then assign that input back to the object.
Example:
I have a dynamic set of products, I’d like to be able to display a table of product names and textfields where the user can enter a price for that product.
Product1 ....... [ textfield_price1 ]
Product2 ....... [ textfield_price2 ]
...
ProductN
[submit_button ]
How do I then map those textfield values back to each product, most of the examples I have seen are standard forms with static information.
Can anyone point me to the right place ?
Thanks in advance.
Typically you’d use map-based syntax, usually with an ID as the key, and a domain object as the value. This is covered in the type conversion docs.
Nutshell: the action has a map of
{ ID => Product }for the form data:Use
[] in the JSP with an ID as thename` attribute value:You could iterate over a collection of products, a pre-filled map, etc.