f-angi
12/4/2015 - 10:41 AM

Spring Date binding

Spring Date binding

public class Bean {
    @DateTimeFormat(pattern = "dd/MM/yyyy")
    private Date fieldDate;
}
<sf:form modelAttribute="testBean">
    <sf:input path="dateField"/>   
</sf:form>    
<mvc:annotation-driven/>
@Controller
@RequestMapping("VIEW")
public class TestController {

    @InitBinder
    public void initBinder(WebDataBinder binder) {

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        sdf.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
    }
    
}