2017-09-26 39 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的工作是否一樣? –