Playframework ad-hoc form validation is executed but does not work as it supose

I have Login class with validate method as follow:

public static class Login {

        /** The customer. */
        @ManyToOne
        @Constraints.Required
        public Customer customer;

        /** The password. */
        public String password;


        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
        public Customer getCustomer() {
            return this.customer;
        }
        public void setCustomer(Customer c) {
            this.customer = c;
        }

        /**
         * Validate.
         *
         * @return the string
         */
        @Transactional
        public String validate() {
            return "Global error";
        }



    }

when I validate form as follow:

if (filledLoginForm.hasGlobalErrors()) {
    return badRequest(views.html.login.render(filledLoginForm));
} else if (filledLoginForm.hasErrors()) {
    return badRequest(views.html.login.render(filledLoginForm));
} else {
    return ok("OK");
}

I get ok page, like there was no error, but in validate method I’ve declared it.

I use play 2.2.6


Source: forms

Leave a Reply