0

I'm getting the following error when I try to retrieve the form results in controller method:

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object 'search' on field 'clients': rejected value [14]; codes [typeMismatch.search.clients,typeMismatch.clients,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [search.clients,clients]; arguments []; default message [clients]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'clients'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.Client] for property 'clients[0]': no matching editors or conversion strategy found]

Model Object looks like this:

 public class SearchForm {
     private String name;
     private List<Client> clients;
     //getters and setters
 }
 public class Client {
     private String name;
     private Int id;
 }

form:

<form:form method="POST", name="searchresults.html" modelattibute="search">
   <form:input path="name"/>
   <form:checkboxes path="clients" items="{clientsList}" itemsValue="id" itemsLabel="name"/>
</form:form>

this form displays the values correctly on the html page but when I click the submit button I get the above error

2
  • here is the form <form:form method="POST", name="searchresults.html" modelattibute="search"> <form:input path="name"/> <form:checkboxes path="clients" items="{clientsList}" itemsValue="id" itemsLabel="name"/> </form:form> this form displays the values correctly on the html page but when I click the submit button I get the above error Commented Aug 9, 2011 at 15:26
  • have you created a property editor or conversion strategy for your class Client? Commented Aug 9, 2011 at 17:50

1 Answer 1

2

The browser will only send a list of client IDs when the form is submitted. How could Spring know how to convert each ID into a Client instance. You either have to tell it how to do, or add a List<String> clientIds property to your bean, and make the form:checkboxes tag use this property instead of clients as its path.

Sign up to request clarification or add additional context in comments.

1 Comment

@JB.. thanks for the reply.. first part.. " how do I tell it to build Client instances from IDs.." I mean the exception occurs at this line in controller public String searchformsubmit(@ModelAttribute("search") SearchForm search){}.. now at what point do I add the code to convert? secondly if I hav the List<Strings> then I cannot display the Client name on the jsp page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.