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

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

    Hello,

    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: http://forum.springsource.org/showth...ient-side-ajax), 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, 02:05 PM.

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

    Example:

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

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

    Code:
    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?

    Comment


    • #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?

      Comment

      Working...
      X