Permalink
Browse files

Add validation

  • Loading branch information...
jamesward committed Apr 1, 2015
1 parent 5e92362 commit df3f19f44781fab2b44c52b4b2a7515d3f1f0d5f
Showing with 9 additions and 3 deletions.
  1. +8 −3 app/controllers/Application.java
  2. +1 −0 app/models/Task.java
@@ -13,9 +13,14 @@ public static Result index() {
public static Result addTask() {
play.data.Form<models.Task> form = play.data.Form.form(models.Task.class).bindFromRequest();
- models.Task task = form.get();
- task.save();
- return redirect(routes.Application.index());
+ if (form.hasErrors()) {
+ return badRequest(index.render("hello, world", form));
+ }
+ else {
+ models.Task task = form.get();
+ task.save();
+ return redirect(routes.Application.index());
+ }
}
public static Result getTasks() {
View
@@ -11,6 +11,7 @@
@Id
public String id;
+ @play.data.validation.Constraints.Required
public String contents;
}

0 comments on commit df3f19f

Please sign in to comment.