简体   繁体   English

使用数据播放框架预先填写表格

[英]Pre-fill form with data Play Framework

I'm using the Play Framework with Java. 我正在将Play Framework与Java配合使用。

I'm trying to pre-fill a form with data and pass it to my template. 我正在尝试使用数据预填充表单并将其传递给我的模板。 The issue doesn't seem to be actually filling the form, but more accessing the values after it has been passed to the template. 这个问题似乎并没有真正填写表格,而是在将其传递给模板后更多地访问了值。

Model: 模型:

public class Job {
    private String title;
    private String employer;

    public void setJobTitle(String title) {
        this.title = title;
    }

    public void setEmployer(String employer) {
        this.employer = employer;
    }

    public String getJobTitle() {
        return title;
    }

    public String getEmployer() {
        return employer;
    }
}

Controller: 控制器:

public static Result editJob() {

    Job job = new Job();
    job.setJobTitle("foo");
    job.setEmployer("bar");
    Form<Job> jobForm = form(Job.class).fill(job);

    String message = "Edit Job";
    return ok(editJob.render(message, jobForm));
}

View: 视图:

@(message: String, jobForm: play.data.Form[model.Job]) {

    @helper.form(action = routes.JobController.editJob(), 'enctype -> "multipart/form-data", 'name -> "jobForm"){
      <input type="text" name="jobTitle" id="jobTitle" value="@jobForm.getJobTitle">
      <input type="text" name="employerName" id="employerName" value="@jobForm.getEmployer">
   }
}

Could somebody please explain how to access the data in the view template. 有人可以解释一下如何访问视图模板中的数据。

Fix: 固定:

@helper.inputText(jobForm(jobForm.get().getJobTitle))

Thanks, 谢谢,

S 小号

Do @jobForm.get().title @jobForm.get().title

you can also use helper input text field 您还可以使用助手输入文本字段

@inputText(jobForm("title"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM