"Play 2.0"-Framework (v. 2.0.1) を使用していますが、日付値のフォーム検証で問題が発生しています。
私のモデルコードの平和:
@Entity
public class Appointment extends Model {
public Date start;
public Date end;
}
私のテンプレートコードの平和:
<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 datepicker を介して日付を選択するか、「yyyy-mm-dd」のような形式で自分自身を入力するか、問題ではありませんが、正しい形式でなければならない場合、コントローラの save() メソッドで検証エラーが発生しますチェック「filledForm.hasErrors()」とエラーメッセージ「間違った日付形式」。
自分で変換を追加する必要がないように、プレイから自動的に変換されると思いました。この問題を解決するにはどうすればよいですか? それはまだプレイ 2.0 の問題ですか?
ありがとうございます。
乾杯、
マルコ