Created
January 17, 2013 18:46
-
-
Save chadothompson/4558475 to your computer and use it in GitHub Desktop.
A Play Tutorial Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers; | |
import models.Task; | |
import play.*; | |
import play.data.Form; | |
import play.mvc.*; | |
import views.html.*; | |
public class Application extends Controller { | |
static Form<Task> taskForm = form(Task.class); | |
public static Result index() { | |
return redirect(routes.Application.tasks()); | |
} | |
public static Result tasks(){ | |
return ok( | |
views.html.index.render(Task.all(), taskForm) | |
); | |
} | |
public static Result newTask(){ | |
Form<Task> filledForm = taskForm.bindFromRequest(); | |
if(filledForm.hasErrors()){ | |
return badRequest(views.html.index.render(Task.all(), filledForm)); | |
} else { | |
Task.create(filledForm.get()); | |
return redirect(routes.Application.tasks()); | |
} | |
} | |
public static Result deleteTask(Long id){ | |
Task.delete(id); | |
return redirect(routes.Application.tasks()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment