I have a fairly complex and big Model
called Task
. In this object I have some heavy custom logic and date time conversion so I decided to make a POJO
for the form since I need custom validation / conversion. But how to bind this POJO back to a Model
?
Is this the correct way:
public static Result save() {
Form<forms.Task> taskForm = form(forms.Task.class).bindFromRequest();
if (taskForm.hasErrors()) {
return badRequest(views.html.tasks.create.render(taskForm));
}
// bind the formValues to our model
Task newTask = form(Task.class).bind(taskForm.data()).get();
newTask.createdBy = User.getLoggedInUserByAlias(session().get("user"));
newTask.save();
return GO_TO_OVERVIEW;
}
Is there a cleaner
way to do it? I think that I am doing this wrong.