Search code examples
formshibernatespring-mvchibernate-validator

Spring MVC Form Hibernate Validator : Cross parameter constraint has no cross parameter validator


Here is my Form

public class TaskForm extends WebForm<TaskModel> {

    public TaskForm(){
        this(new TaskModel());
    }

    public TaskForm(TaskModel form) {
        super(form);
    }


    @NotNull
    @NotEmpty
    public void setName(String taskName){
        target.setTaskName(taskName);
    }


    @NotNull
    @NotEmpty
    public void setDescription(String description){
        target.setDescription(description);
    }

    public void setStartDate(DateTime startDate){
        target.setStartDate(startDate);
    }

    public DateTime getStartDate(){
        return target.getStartDate();
    }

    @DateTimeFormat(pattern = "MM/dd/yyyy")
    public void setEndDate(DateTime endDate){
        target.setEndDate(endDate);
    }

    public DateTime getEndDate(){
        return target.getEndDate();
    }

    public String getName(){
        return target.getTaskName();
    }

    public String getDescription(){
        return target.getDescription();
    }
}

When I submitted the form it threw me an Exception.

HTTP Status 500 - Request processing failed; nested exception is javax.validation.ConstraintDefinitionException: HV000154: Cross parameter constraint org.hibernate.validator.constraints.NotEmpty has no cross-parameter validator.

What caused this problem?


Solution

  • Try moving your @NotNull and @NotEmpty validation constraint in the getter. Change your form like this

    public class TaskForm extends WebForm<TaskModel> {
    
        public TaskForm(){
            this(new TaskModel());
        }
    
        public TaskForm(TaskModel form) {
            super(form);
        }
    
        public void setName(String taskName){
            target.setTaskName(taskName);
        }
    
    
    
        public void setDescription(String description){
            target.setDescription(description);
        }
    
        public void setStartDate(DateTime startDate){
            target.setStartDate(startDate);
        }
    
        public DateTime getStartDate(){
            return target.getStartDate();
        }
    
        //@DateTimeFormat(pattern = "MM/dd/yyyy")
        public void setEndDate(DateTime endDate){
            target.setEndDate(endDate);
        }
    
        public DateTime getEndDate(){
            return target.getEndDate();
        }
    
        @NotNull
        @NotEmpty
        public String getName(){
            return target.getTaskName();
        }
    
        @NotNull
        @NotEmpty
        public String getDescription(){
            return target.getDescription();
        }
    }