3
I have the following piece of code in my .jsp
, in which the objective 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>
The bind is held 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 fires 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 it always triggers the error below conversion, but as far as I know natively the Spring MVC is able to perform bind with list type 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: Cannot Convert value of type [java.lang.String] to required type [br.com.joocebox.model.Passenger] for Property 'Passenger[0]': no matching Editors or Conversion Strategy found]