I have the following code snippet in my .jsp
, in which the purpose is to dynamically list a passenger list per customer.
<f:form id="service-item-form" action="${action}" modelAttribute="serviceItem" method="post">
<ul id="list-of-passenger-service-item" class="list-cadastro">
<c:choose>
<c:when test="${empty customer.passenger}">
<li>
<b>O Cliente não possui passageiros vinculados.</b>
</li>
</c:when>
<c:otherwise>
<f:checkboxes items="${customer.passenger}" path="passenger" element="li" itemValue="id"/>
</c:otherwise>
</c:choose>
</ul>
</f:form>
bind is carried out in my bean OpenService.java
in the passenger attribute, as shown below:
@Entity
@Table(name = "open_service")
public class OpenService implements Serializable{
//other attributes
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "service_passenger", joinColumns = @JoinColumn(name = "service_id"), inverseJoinColumns = @JoinColumn(name = "passenger_id"))
private List<Passenger> passenger;
//Getter and Setter
}
Finally it triggers an action with the following signature:
@RequestMapping(value = "/add-service/{id}", method = RequestMethod.POST)
public String addService(@ModelAttribute("serviceItem") OpenService openService, @PathVariable Long id) {
//business rules
return "redirect:/acme"
}
But the problem is that it always triggers the error below conversion, but as far as I know natively Spring MVC is able to bind with list objects
Field error in object 'serviceItem' on field 'passenger': rejected value [7]; codes [typeMismatch.serviceItem.passenger, typeMismatch.passenger, typeMismatch.java.util.List, typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [serviceItem.passenger, passenger]; arguments []; default message [passenger]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'passenger'; nested exception is java.lang.IllegalStateException: Can not convert value of type [java.lang.String] to required type [br.joocebox.model.Passenger] for property 'passenger [0]': no matching editors or conversion strategy found]