Results 1 to 3 of 3

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

  1. #1
    Join Date
    Feb 2012
    Location
    Poland
    Posts
    6

    Default 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 at 01:05 PM.

  2. #2
    Join Date
    Feb 2012
    Location
    Poland
    Posts
    6

    Default

    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?

  3. #3

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •