I have a question about Spring, particularly the MVC component. I have a jsp page which contains the following code.
<form:form modelAttribute="sentenceModelAttribute"
method="POST" action="sentencemanagement.htm">
<table class="activity">
<tr>
<th/>
<th>ID</th>
<th>Description</th>
<th>Action</th>
<th>Decision</th>
</tr>
<c:forEach items = "${model.allSentences}" var="sentence">
<tr>
<td><form:radiobutton path="id" value="${sentence.id}"/></td>
<td>${sentence.id}</td>
<td>${sentence.description}</td>
<td>${sentence.action}</td>
<td>${sentence.decision}</td>
</tr>
</c:forEach>
</table>
<input type="submit" name="modify" value="Modify"/>
<input type="submit" name="cancel" value="Cancel"/>
</form:form>
The POST is connected to a method in a controller and this method has an argument sentenceModelAttribute. Currently, this argument has all the values of the object from the selected radiobutton. This is indeed what I want.
My question is how does it do that? How does it link the object I selected from the table with what appears in modelAttribute?
Your radiobutton has
idas the path attribute. This path is relative tosentenceModelAttributewhich is set in your form tag, so the value of the radiobutton is bound tosentenceModelAttribute.id.