Reputation: 1269
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.
Upvotes: 2
Views: 8548
Reputation: 827
Just add a nested Jsp form with a single submit button example see below
<form:form method="POST" modelAttribute="applicationGeneralInformation">
<div class="section2">
<h2>General Informaion</h2>
<form:input type="hidden" path="id" id="id"/>
<label for="app_version">Version</label>: <form:input type="text" id="app_version" path="version"/><br/>
<label for="app_func_desc">Description</label>: <form:input type="text" id="app_func_desc"
path="functionalDescription"/><br/>
<label for="app_sec_func">Functions</label>: <form:input type="text" id="app_sec_func"
path="securityFunctions"/><br/>
</div>
<div class="section2">
<h2>Application Content</h2>
<form:form method="POST" modelAttribute="applicationContent">
<div>
<h3>CIA Rating</h3>
<label for="CIARating">CIA Rating</label>: <form:select type="text" id="CIARating" path="CIARating">
<form:option value="1">1</form:option>
<form:option value="2">2</form:option>
<form:option value="3">3</form:option>
<form:option value="4">4</form:option>
</form:select><br/><br/>
</div>
<div>
<h3>Business Continuity and Disaster Recovery</h3>
<div>
<h4>RTO</h4>
<label for="RTO">RTO</label>: <form:select type="text" id="RTO" path="RTO">
<form:option value="1">< 2<sub>Hrs</sub></form:option>
<form:option value="2">2<sub>Hrs</sub>-4<sub>Hrs</sub></form:option>
<form:option value="3">4<sub>Hrs</sub>-48<sub>Hrs</sub></form:option>
<form:option value="4">> 48<sub>Hrs</sub></form:option>
</form:select><br/>
</div>
<div>
<h4>RPO</h4>
<label for="RPO">RPO</label>: <form:input type="text" id="RPO" path="RPO"/><br/>
</div>
</div>
</form:form>
<input type="submit" value="Submit">
</div>
</form:form>
Upvotes: 0
Reputation: 65
Yup, im agree with nickdos. Btw, dont forget to put those two classes name in path:
example :
<spring:bind path="user.status">
<appfuse:label styleClass="control-label" key="id.user.maritalStatus"/>
<form:input path="user.status" cssClass="form-control" id="status" />
</spring:bind>
Upvotes: 0
Reputation: 8414
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.
Upvotes: 4