Hi, I am new in Spring Framework, I have a question to ask. In my project, the UI part transfer me a Array of Object, for example, a array of Object PERSON, each PERSON object contain Birthday,FirstName,LastName. If UI part transfer me one PERSON object, I can handle it, but how if UI part transfer me a array of Object PERSON, which include PERSON A, PERSON B... within one command object. How can my controller get the command object and store each object to database separately???
you would have to design your command object appropriately.
example of command object for handling a single person.
Code:
public class Person implements ... Serialzable{
// assuming person has a address and the address is modelled in a separate class.
private Address address;
// getters and setters for the address.
// important thing is create the instance of address object in the constructor.
public Person(){
address = new Address();
}
}
}
in the jsp you can bind the user's keyed in values to the person object if you use.
Code:
<form:form commandName="person">
<form:input path="address.street">
</form>
example of command object for handling a multiple person.
Code:
public class Persons{
private Collection person;
// getters and setters for the person.
// important thing is create the instance of personobject in the constructor.
public Persons(){
person= new ArrayList();// if you are using jdk5 you can use generics.
}
}
}
In the jsp you can bind the values like the following.
Code:
<form:form commandName="person">
<form:input path="person[0].address.street">
<form:input path="person[1].address.street">
</form>