Multiple modelattributes in a JSP with Spring

dgmora picture dgmora · Feb 23, 2012 · Viewed 7.2k times · Source

What I am trying to accomplish is using one single form, submit multiple modelattributes with Spring and JSP.

With one I know how to do it, mapping the model with the tag form:form.

But, if I want to get two modelAttributes in the controller method with the annotations @ModelAttribute how should I do it? Is it even possible? I am aware this is not so common, but I would like to know if it is possible.

Answer

nickdos picture nickdos · Feb 24, 2012

AFAIK, you can only bind a form with a single object. If you have two classes, then you can create a single class that references the other two classes and then bind with that class.