我只是想将我的表单传递给我的控制器,无论我尝试什么,我都会收到此错误:
render(play.api.data.Form<models.Service>) in 'null' cannot be applied to (play.data.Form<models.Service)
错误行:
return ok(info.render(sServiceForm));
Info.scale.html - 查看
@(serviceForm : Form[Service])
@import helper._
@main("Service info") {
<h1>Service Information</h1>
@helper.form(action = routes.Services.save()) {
<fieldset>
<legend>Service</legend>
@helper.inputText(serviceForm.field("code"), '_label -> "Code")
@helper.inputText(serviceForm.field("description"), '_label -> "Description")
@helper.inputText(serviceForm.field("description"), '_label -> "Description")
</fieldset>
<input type="submit" value="Save" />
}
}
Service.java - 模型
package models;
import com.avaje.ebean.Model;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* Created by James on 3/4/2016.
*/
// Telling play framework that this is a class thats going to map as a model to save service records
@Entity
public class Service extends Model {
// Internal ID to reference a certain activity
@Id
public String code;
public String description;
}
Services.java - 控制器
package controllers;
import models.Service;
import play.mvc.Controller;
import play.mvc.Result;
import play.data.Form;
import views.html.services.info;
/**
* Created by James on 3/4/2016.
*/
public class Services extends Controller {
// Creating static class variable, calling static method and passing our model class.
//private static final Form<Service> sServiceForm = Form.form(Service.class);
private static final Form<Service> sServiceForm = play.data.Form.form(Service.class);
public Result list() {
return TODO;
}
public Result addService() {
return ok(info.render(sServiceForm));
}
public Result save()
{
return TODO;
}
}
如果我注释掉:
private static final Form<Service> sServiceForm = Form.form(Service.class);
并将我的站点更改addService
为return TODO;
可以正常编译的站点,并且可以很好地完成整个过程。即使我仍在返回 TODO,此行也会中断站点:
private static final Form<Service> sServiceForm = Form.form(Service.class);