I'm currently looking at the Play! Framework for Java, and I've run into a pretty curious error:
I've got a model with the following required fields (no other fields except an id)
@Lob
@Constraints.Required
private String content;
@Constraints.Email
@Constraints.Required
private String email;
@Constraints.Required
private String title;
I've got the following methods in my Controller:
public static Result createEntry() {
Form<BlogEntry> filledForm = blogEntryForm.bindFromRequest();
if (filledForm.hasErrors()) {
Logger.debug(filledForm.data().toString());
Logger.debug(filledForm.errors().toString());
return badRequest(newentry.render(filledForm));
}
BlogEntry entry = filledForm.get();
entry.save();
return redirect(routes.BlogController.index());
}
public static Result newEntry() {
return ok(newentry.render(blogEntryForm));
}
And the view looks like this:
@(blogform: Form[BlogEntry])
@import helper._
@main("New Blog Entry") {
@form(routes.BlogController.createEntry()) {
@if(blogform.hasErrors) {
Errors in form
}
<fieldset>
<div>
@inputText(blogform("email"), '_label -> "Email")
</div>
<div>
@inputText(blogform("title"), '_label -> "Title")
</div>
<div>
@inputText(blogform("content"), '_label -> "Content")
</div>
<button type="submit">Submit</button>
</fieldset>
}
}
Now when I navigate to the form in my browser, and enter some data, then click "submit", I get redirected to the form, so the badRequest portion of the code was called. So I started logging the output of both form and validation errors, and this came out:
[debug] application - {content=test, title=test, [email protected]}
[debug] application - {content=[ValidationError(content,error.required,[])], title=[ValidationError(title,error.required,[])], email=[ValidationError(email,error.required,[])]}
The data is definitely there, and when I'm redirected to the form after submitting, the fields are still filled with the correct data. Am I missing something obvious here?