Reputation: 97
I'm passing several values from my jsp to my controller.
<form method="POST" action="${url_save}" modelAttribute="sprav">
<tr>
<c:forEach var="columnName" items="${sprav.columnName}">
<td><input name="${columnName}"></input></td>
</c:forEach>
</tr>
<tr>
<td><input type="submit" value="submit"></input></td>
</tr>
</form>
As you can see, the number may vary. I want to use the columnNames as names of my columns in my database (they match) and insert values of these inserts to the database later on into respective columns But, if this list of columnNames is dynamic, how do I recieve these attributes in the controller? Binding them through jstl form:form didn't work as I don't know which table (and List of columnNames will be chosen) dynamically, and I dont have the getters/setters for the columns themselves, only for the whole lists. If you need extra data, feel free to ask!
Upvotes: 1
Views: 486
Reputation: 441
You can try: ${columnName}[]
<form method="POST" action="${url_save}" modelAttribute="sprav">
<tr>
<c:forEach var="columnName" items="${sprav.columnName}">
<td><input name="column[]"></input></td>
</c:forEach>
</tr>
<tr>
<td><input type="submit" value="submit"></input></td>
</tr>
</form>
Then in the controller, you can map it with an array of String
or List<String>
Upvotes: 1