Reputation: 1873
My Validator Class
public class ProductValidator implements Validator {
public void validate(Object obj, Errors errors) throws ValidatorException {
Product product =(Product)obj;
if("NONE".equals(product.getCategory())){
errors.rejectValue("category","Category Required");
}
}
My jsp
<form:select path="category" cssClass="add">
<form:option value="NONE" label="--- Select Category ---"/>
<form:options items="${categoryList}" itemValue="categoryId" itemLabel="categoryName"/>
</form:select>
<form:errors path="category" cssClass="error"> </form:errors>
When I submit the form without selecting any option it gives error as,
Failed to convert property value of type java.lang.String to required type com.main.java.Category for property category; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.main.java.Category] for property category: no matching editors or conversion strategy found
Any thing wrong here?
Please help.....
Upvotes: 1
Views: 525
Reputation: 18639
If nothing selected you are submitting "NONE" String to your controller.
<form:option value="NONE" label="--- Select Category ---"/>
This is why you are getting this exception
Upvotes: 1