Skip to content

Instantly share code, notes, and snippets.

@chadothompson
Created January 17, 2013 18:46
Show Gist options
  • Save chadothompson/4558475 to your computer and use it in GitHub Desktop.
Save chadothompson/4558475 to your computer and use it in GitHub Desktop.
A Play Tutorial Controller
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