Announcement Announcement Module
No announcement yet.
How to add values from several fields of one form to command object list. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to add values from several fields of one form to command object list.


    I am still new to Spring MVC and I have some problems with command object list.

    I have dynamically generated form in JSP witch contains some fields. I would like to add all values from these fields to my command object list after clicking 'submit' button.

    When I have only one field, it is not a problem to add its value to the list (eg. here:, but how to make it when I have many form fields?

    I would be grateful for any help.
    Last edited by PiratDrogowy; Feb 7th, 2012, 01:05 PM.

  • #2
    OK, the solution of above problem is very simple to achieve when the list contains String values.


    public class BeanService{
    private List<String> list = new ArrayList<String>(); //setters and getters
    and the JSP:

    <form:form commandName="beanService"
    	<c:if test="${fn:length(someList) > 0}">
    		<c:forEach items="${someList}" var="ff">
    			"${ff.label}": <form:input path="list"/>
    		<input type="submit" value="Add">
    But now the problem is when the list in BeanService class holds custom type objects:
    public class Bean{
    private List<CustomType> list = new ArrayList<Custom>(); //setters and getters
    and the CustomType looks like:

    public class CustomType{
    private String value; private String type; //setters and getters...
    and values of 'value' and 'type' in CustomType comes from above JSP.
    Any help?


    • #3
      Can you show what the <form:input> tags look like for your second (non-working) case, and what the controller handler method looks like?