Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation 播放2.0表单日期验证失败_Validation_Date_Model_Playframework 2.0 - Fatal编程技术网

Validation 播放2.0表单日期验证失败

Validation 播放2.0表单日期验证失败,validation,date,model,playframework-2.0,Validation,Date,Model,Playframework 2.0,我正在使用“Play2.0”-框架(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" /> <!--

我正在使用“Play2.0”-框架(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());
        }
    }
}
公共类预约扩展控制器{
静态表单appointform=表单(Appointment.class);
//在调用表单页上
公共静态结果创建(){
返回ok(create.render(“create”,appointmentForm));
}
//在保存表单数据时调用
公共静态结果保存(){
Form filledForm=appointmentForm.bindFromRequest();
if(filledForm.hasErrors()){
返回错误请求(
create.render(“create”,filledForm)
);
}否则{
create(filledForm.get());
返回重定向(routes.Appointment.index());
}
}
}
如果我通过jquery ui datepicker选择一个日期,或者以“yyyy-mm-dd”之类的格式键入自己的日期,或者不重要,但必须是正确的格式,那么我会在控制器save()方法中遇到验证错误,并检查“filledForm.hasErrors()”和错误消息“错误的日期格式”

我想它会从游戏中自动转换,这样我就不必自己添加转换了。我能做些什么来解决这个问题?这仍然是play 2.0的问题吗

谢谢你

干杯


马可

我想你必须定义日期的格式。有关自定义格式化程序,请参见。也许需要定制活页夹,请参见 就像一些提示给你一个方向。希望有人能给你一个更好的答案