Thursday, 5 September 2013

Todolist Java example delete method acting odd

Todolist Java example delete method acting odd

I have an issue with Play framework 2.1.3 while testing the differences
between Java and Scala implementations. The example with Scala worked
without issues and I was able to test it successfully very fast.
But with Java implementation, I hit a pump with delete method. For some
odd reason, it is not working as said example.
Regardless if I have Application.deleteTask method running
Task.delete(id); or return TODO;, when running the actual
todolist-application, the method is never used? So where is the problem?
Here are the sources (all methods finalized as in the said tutorial):
apps/controllers/Application.java
package controllers;
import java.util.*;
import play.*;
import play.mvc.*;
import play.data.*;
import models.*;
import views.html.*;
public class Application extends Controller {
static Form<Task> taskForm = Form.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());
}
}
apps/models/Task.java
package models;
import java.util.*;
import play.db.ebean.*;
import play.data.validation.Constraints.*;
import javax.persistence.*;
@Entity
public class Task extends Model {
@Id
public Long id;
@Required
public String label;
public static Finder<Long,Task> find = new Finder(
Long.class, Task.class
);
public static List<Task> all() {
return find.all();
}
public static void create(Task task) {
task.save();
}
public static void delete(Long id) {
find.ref(id).delete();
}
}

No comments:

Post a Comment