spring converter in initbinder code example
Example: spring converter in initbinder
public class CategoryEditor extends PropertyEditorSupport {
@Override
public void setAsText(String text) {
Category c = new Category(text);
this.setValue(c);
}
@Override
public String getAsText() {
Category c = (Category) this.getValue();
return c.getName();
}
}
public class MyController {
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Category.class, new CategoryEditor());
}
...
}