Package controllers

Source Code of controllers.Application

package controllers;

import java.util.List;

import play.modules.spring.Spring;

import models.Task;
import play.data.Form;
import play.mvc.Controller;
import play.mvc.Result;
import services.TaskService;
import views.html.addtask;
import views.html.index;

public class Application extends Controller {

  static Form<Task> taskForm = form(Task.class);

  private static TaskService getTaskService(){
    return Spring.getBeanOfType(TaskService.class);
  }
 
  public static Result index() {
    return redirect(routes.Application.tasks());
  }

  public static Result tasks() {
    List<Task> items = getTaskService().allTasks();
    return ok(index.render(items));
  }

  public static Result addTask() {
    Task defaultTask = new Task();
    defaultTask.label = "my new task";
    defaultTask.comment = "ysdgs";
    taskForm = taskForm.fill(defaultTask);
    return ok(addtask.render(taskForm));
  }

  public static Result newTask() {
    Form<Task> filledForm = taskForm.bindFromRequest();
    if (filledForm.hasErrors()) {
      return badRequest(views.html.addtask.render(filledForm));
    } else {
      getTaskService().create(filledForm.get());
      return redirect(routes.Application.tasks());
    }
  }

  public static Result deleteTask(Long id) {
    getTaskService().delete(id);
    return redirect(routes.Application.tasks());
  }
}
TOP

Related Classes of controllers.Application

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.