Suppose I want to fill two or three different beans with Spring 3 开发者_开发知识库mvc how do I do that given that <form:form>
only supports one modelAttribute
? And what if I have some nested beans?
Obviously I don't want to create a "BIG" bean that then I use to fill'em all...
I think the simplest solution is create a new command class and use object composition.
public class MyCommandClass implements Serializable {
private MyFirstBean myFirstBean;
private MySecondBean mySecondBean;
// other beans, getters and setters, etc.
}
Your form:
<form:form modelAttribute="myCommand">
<form:input path="myFirstBean.someProperty" ... />
<form:input path="mySecondBean.someOtherProp" ... />
</form:form>
精彩评论