I am specifying the property editors for my controller as :
@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
binder.registerCustomEditor(Date.class, editor);
}
which work fine until I call the following method in an AJAX call.
@RequestMapping(value = "searchCriteria", method = RequestMethod.GET)
public @ResponseBody Set<SearchCriteria> loadSearchCriterias(){
// call service method to load criterias
Set<SearchCriteria> criterias = new HashSet<SearchCriteria>();
SearchCriteria sampleCriteria = new SearchCriteria();
sampleCriteria.setStartDate(new Date());
criterias.add(sampleCriteria);
return criterias;
}
In this case, the due date in SearchCriteria
is not being converted to the proper format by the custom property editor. How can I make property editors to be applied even when I am returning an object through an AJAX call ?
public class SearchCriteria{
Date startDate;
String name;
// getter setters
}