When the form is submitted, I can associate the appropriate first name with the last by array index. I cannot have unique names for the first and last name entries as I might have multiple sets of the same.
This model works fine for me currently. Now, if I were to place an <option> selection as part of each set, how can I make this association?
Thanks in advance. Please assist.
Never be satisfied with anything less than the best and you will surely pass the test...
Thanks for the response. I am using Struts to handle the form population. If I define an array in the form such as String firstName; String lastName; with set/gets, BeanUtils.copyProperties() fails.
I am hoping not to have individual elements defined like firstName1 and having getFirstName1() etc due to the dynamic nature of the elements.
Does Struts not have a concept of a dyanmic form to handle just such situations?
I've moved this to the Struts forum for people who use it to comment.
Joined: Jan 15, 2002
I was not using setFirstName(int index, String val).Its working great now. I however am still unsure as to how to get this to work if I have an options field as part of each firstName/lastName set and how to associate it with the right element.
You woulld use the same principle in creating a dropdown box for each name. Suppose you wanted to provide a field for t-shirt size with options samll, medium or large for each name. Here's how you'd do it
Then, in your ActionForm, code a setTShirtSize(int index, String size) method.
Just a note on style: This method, while it works, is not making very good use of object oriented design. A better design would be to have a Person object with properties for first name, last name, t-shirt size, etc. Then have an array or an ArrayList of Person objects in your ActionForm. [ June 14, 2006: Message edited by: Merrill Higginson ]
Thanks much for the response. The example you have provided works fine if the selection is of one single element from the options. If I were to select multiple, then wouldnt I need to pass in an array to setOption(int index, String value) ?
Joined: Feb 15, 2005
Yes, you are right. In this case, the tShirtSize property would have to be a double-dimensioned array, or of type String.