我正在尝试自定义Play framework -Computer database with Java示例。但是,我似乎无法让“编辑”页面上的提交按钮起作用(带注释)。这是表格:
@(id: Long, computerForm: Form[Provider])
@import helper._
@implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.render) }
@main {
<h1>Provide fb*emphasized text*</h1>
@form(routes.Application.update(id)) {
<fieldset>
@inputText(computerForm("fb"), '_label -> "Feedback", '_help -> "")
@inputText(computerForm("rating"), '_label -> "Rating", '_help -> "")
</fieldset>
<div class="actions">
<!-- This button does nothing!-->
<input type="submit" value="Submit fb!" class="btn primary"> or
<a href="@routes.Application.list()" class="btn">Cancel</a>
</div>
}
}
这是来自update
的{{1}}方法:
Application.java
我做错了什么?
编辑 - 更多细节。
型号: Provider.java
public static Result update(Long id) {
Form<Provider> computerForm = form(Provider.class).bindFromRequest();
if(computerForm.hasErrors()) {
return badRequest(editForm.render(id, computerForm));
}
computerForm.get().update(id);
flash("success", "Provider " + computerForm.get().fullname + " has been updated");
return GO_HOME;
}
}
问题2:单击按钮时会发生什么:没有任何可见的内容。但是,当我看起来非常接近时,它似乎重定向到同一页面(更新页面)。但基于控制器,我希望它能够根据/**
* Company entity managed by Ebean
*/
@Entity
public class Provider extends Model {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
@Constraints.Required
public String fullname;
public String tech;
public String experience;
public String email;
public String feedback;
public int rating;
/**
* Generic query helper for entity Provider with id Long
*/
public static Model.Finder<Long, Provider> find = new Model.Finder<Long, Provider>(Long.class, Provider.class);
public static Map<String, String> options() {
LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
for (Provider c : Provider.find.orderBy("tech").findList()) {
options.put(c.id.toString(), c.fullname);
}
return options;
}
public static Page<Provider> page(int page, int pageSize, String sortBy, String order, String filter) {
return find.where().ilike(sortBy, "%" + filter + "%").findPagingList(pageSize).setFetchAhead(false)
.getPage(page);
}
变量返回主页。
Application.java
GO_HOME
答案 0 :(得分:1)
请原谅我,我对Scala最熟悉,但我怀疑你在提交时未能通过表单验证并返回同一页面:
if(computerForm.hasErrors()) {
return badRequest(createForm.render(computerForm));
}
在Provider
课程中fullname
看起来像defining a constraint:
@Constraints.Required
public String fullname;
但您未在表单中加入fullname
。您可以从模型中删除约束或将字段添加到表单吗?
与您的失败无关,您在视图中引用了表单字段fb
,但提供商模型没有该值?它应该是feedback
?