未填写表格

时间:2015-08-08 12:50:42

标签: java forms playframework playframework-2.3

在我的应用中,用户填写的表格包含他的信息(学习计划,学分,性别,年龄等)。 Play验证数据(例如,取决于学习计划,获得的学分有上限),并且在错误时返回badRequest(),其中包含填写了所提供数据的表单。

问题是,填充的表单不会呈现。

控制器代码:

Form<UserData> bound = form(UserData.class).bindFromRequest();
    if (bound.hasErrors()){
        //retrieve data from form
        Map<String, String> map = bound.data();
        //build a new UserData object, filled with the submitted values
        UserData data = new UserData(map);
        //fill new Form instance with object
        Form<UserData> dataForm = form(UserData.class).fill(data);
        flash("error", "Form has errors!");
        return badRequest(
                userDataForm.render(dataForm)
        );

我的模板如下所示:

<fieldset>
                <div class="col-md-12">
                    @bootstrap.select(userDataForm("program"),
                        optionList = models.survey.user.StudyProgram.getNameList,
                        label = "Program of Study",
                        help ="Chose the program of study you are currently enrolled in")
                </div>
                <hr>
                <div class="col-md-12">
                    @bootstrap.text(userDataForm("age"),
                        label = "Age",
                        help = "Chose your age",
                        placeholder = "Age"
                    )
                </div>
                <hr>
                <div class="col-md-12">
                    @bootstrap.select(userDataForm("gender"),
                        optionList = scala.List("Female","Male"),
                        label = "Gender",
                        help ="Chose the gender you identify with")
                </div>
                <hr>
                <div class="col-md-12">
                    @bootstrap.text(userDataForm("credits"),
                        label = "How many credits (Leistungspunkte) have you earned so far (maximum: 180 for B.Sc., 120 for M.Sc.)?",
                        help = "How many credits have you earned so far?",
                        placeholder = "Credits"
                    )
                </div>

为什么填写的表格没有呈现?我看到的只是一个空的表单页面,好像没有输入任何值。我可以看到部分Object具有我想要的所有值。

我还尝试创建一个值-HashMap并从中填充填充的Form:

Map<String, String> map = bound.data();
Form<UserData> form = form(UserData.class).bind(map, "program", "age", "gender", "credits");

0 个答案:

没有答案