2012-06-22 31 views
1

我使用「播放2.0」 -framework(訴2.0.1),並運行到一些麻煩與日期值的表單驗證。播放2.0形式的日期驗證失敗

和平的我的模型代碼:

<input type="text" id="start" name="start" placeholder="yyyy-mm-dd" /> 

<!-- ALSO tested with chrome beta v. 20 with html5 support--> 
<input type="date" id="end" name="end" placeholder="yyyy-mm-dd" /> 

我的控制器:

public class Appointment extends Controller { 
    static Form<Appointment> appointmentForm = form(Appointment.class); 

    //on calling form page 
    public static Result create() { 
     return ok(create.render("create", appointmentForm)); 
    } 

    //called on saving form data 
    public static Result save() { 
     Form<Appointment> filledForm = appointmentForm.bindFromRequest(); 
     if (filledForm.hasErrors()) { 
      return badRequest(
        create.render("create", filledForm) 
      ); 
     } else { 
      Appointment.create(filledForm.get()); 
      return redirect(routes.Appointment.index()); 
     } 
    } 
} 

如果我選擇通過jQuery UI的日期選擇日期或

我的模板代碼
@Entity 
public class Appointment extends Model { 
    public Date start; 

    public Date end; 
} 

和平以「yyyy-mm-dd」的格式輸入我自己的內容或無關緊要,但必須是正確的格式,我遇到了一個vali在我的控制器save()方法錯誤 - 檢查「filledForm.hasErrors()」的方法和錯誤消息「錯誤的日期格式」。

我認爲它會自動從遊戲中進行轉換,這樣我就不用自己一個添加皈依。我能做些什麼來解決這個問題?玩2.0還是個問題嗎?

Thanky you。

乾杯,

馬爾科

回答