Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I bind collection attributes to a form in Spring MVC

Tags:

People also ask

What is form binding in Spring MVC?

Form Handling Support in Spring MVC Model: basically a POJO (Plain Old Java Object) class is created to bind form fields with properties of the object. This object will be put into the model (model object).

How can you read only on parameter value from a form in Spring MVC?

In Spring MVC, the @RequestParam annotation is used to read the form data and bind it automatically to the parameter present in the provided method.

What is form backing object in Spring MVC?

Form Backing Object/Command Object This is a POJO that is used to collect all information on a form. It contains data only. It is also called a Command Object in some Spring tutorials. For example, an add a new car form page will have a Car form backing object with attribute data such as Year, Make and Model.

What does Spring bind do?

The spring:bind tag provides you with support for evaluation of the status of a certain bean or bean property.


I'm trying to bind one of my model objects to the fields of a form, using Spring-MVC. Everything works fine, except that one of the attributes of the model object is an unordered collection. Doing something like

    <c:forEach items="${m.items}" var="i" varStatus="itemsRow">
      <form:input path="items[${itemsRow.index}]"/>
    </c:forEach>
    <form:errors path="items" />

would work fine for a List-type property, but for a Set throws an error when, upon submit, it tries to bind input field content to object attributes.

Is there something in Spring that works out of the box with Sets?