How do I validate required fields on a form within the controller? For example, my entity has the creation_date field, but I do not put this field within the form in the view, as it is required I need to set it out of view, ie, within the controller. Does anyone have any examples of how to do this?
Thanks
Edit: I'm sorry, I did not make myself clear. I have a field in my entity annotated with @NotNull and I just need to fill value in controller (task.setCreationDate(new Date())). The field doesn't need to be validated in view scope. Example:
public static Result newTask() {
Form<Task> form = taskForm.bindFromRequest();
if (form.hasErrors()) {
return badRequest("Error");
} else {
Task task = form.get();
task.setCreationDate(new Date());
taskDAO.save(task);
return redirect(routes.Application.tasks());
}
}
In the code above, the form isn't validated (returns hasErrors()).