I have a Spring checkbox:
<spring:url value="/car/save" var="formUrl"/>
<form:form action="${formUrl}" method="POST" modelAttribute="car">
<div class="form-group">
<label for="equipment">Equipment</label>
<form:checkboxes path="equipment" id="equipment" items="${equipmentList}"/>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form:form>
Controler looks like this:
@RequestMapping(value="/add",method=RequestMethod.GET)
public String addCar(Model model){
List<String> equipment = new LinkedList<>(Arrays.asList(new String[]{"AC","ABS","ESP","GPS","Cabrio"}));
model.addAttribute("car",new Car());
model.addAttribute("equipmentList",equipment);
return "addCar";
}
and Car entity:
@Entity
@Table(name="CAR")
public class Car {
@Id
@Column(name="CAR_ID")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long carId;
@Column(name="EQUIPMENT")
private String[] equipment;
}
When I first tried to persist the Car entity, I got an exception because value was too long for the db table. I changed it to 200 chars but now I end up with:
How can I store a value from Spring checkbox?