开发者

Hibernate validator: how to handle rollover? (28/14/2009 becomes 28/2/2010)

I'm using the hibernate validator to validate my forms. I'm having the "problem" that the 9th of the 14th month becomes the second month in the next year. (just en example of a scenario).

I was wondering how I could prevent the default conversion and instead show a custom error message for it.

Does anyone also know how I can display an approperiate message if my custom editor throws an IllegalArgumentException?

@InitBinder
    public void initBinder(WebDataBinder binder) {
        C开发者_如何学PythonustomDateEditor editor = new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true);
        binder.registerCustomEditor(Date.class, editor);
    }

I registred a customEditor because spring-portlet-mvc had some issues with the binding.


This behaviour is controlled by DateFormat.setLenient() and has nothing to do with validation (with setLentient(false) it produces a type mismatch error at the binding phase):

DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
df.setLenient(false);
CustomDateEditor editor = new CustomDateEditor(df, true); 
binder.registerCustomEditor(Date.class, editor); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜