2017-09-26 227 views
0

当我尝试输入日期格式40/40/2017时,spring webflow将其转换为快速时间并将其转换为有效日期。这可以避免验证器引发的任何错误。有没有什么办法可以使这个无效而无需将该变量转换为字符串?Spring webflow中允许的月份和日期无效

回答

0

由于有在Spring MVC几种方法来解决这些问题,如使用initBinder通过验证。首先这个日期值传递给initBinder,这样它会抛出一个错误(在审定的时间)。
试试这个,可能是有益的

@InitBinder 
public void initBinder(WebDataBinder binder) { 
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); 
    binder.registerCustomEditor(Date.class, new 
             CustomDateEditor(dateFormat,true)); 
} 
+0

而且你可能想'dateFormat.setLenient(假)'在你的粘结剂,因此像月份值= 40 *不*接受。 – dbreaux

+0

春季webflow的工作是否一样? –