I have a Struts 2 Form from which I am entering fields including Email IDs.Now user can have click on add to dynamically add new text box for entering more email Ids. So the names of textboxes in such a case would be created on user click of add more button. But the problem is that field names in Struts 2 have to be properties of Action class with setter getter methods. But how can i create property and setter getter for a textbox whose name is not yet known. ? Suppose there are 5 fields as text box and I have 5 properties in action class with setter getter.Now I click add button and dynamically generate a new text box for additional emailId.How can i have this name as property of action class when this name is known only dynamically on click of add button?
Use an indexed property (yes, that page is for Struts 1.x, but the principal applies in Struts 2.x). Basically the getter/setter on your action or data object should take a collection and the name of your text box should be the collection name plus an index.
I've same requirement now. I've a bundle of text boxes in one <li><table><tr>1</tr><tr>2</tr><tr>3</tr><tr>...</tr></table></li>. So, when I click on add button, it produces another <li><table>bundle of text inputs</table></li>. My problem is, how to create dynamic setters and getters for all inputs. here is my all source code. Please guide me or modify the code, the way it has to be.
Ramakrishna Udupa wrote:
Please reply as soon as possible
Please do not post the same question more than once. I've already linked to a relevant example in your other post. Since you found Monica's post you can obviously search the forum for other examples, of which there are many. We will not do your work for you. If you show some effort we would be glad to help you.