3

这是我的表格

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();
    }
}

当我提交表单时,它给了我一个异常。

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.

是什么导致了这个问题?

4

2 回答 2

4

尝试在 getter 中移动您的 @NotNull 和 @NotEmpty 验证约束。像这样改变你的表格

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();
    }
}
于 2013-08-11T07:24:57.570 回答
1

Bean constraints must be on the fields or getters of a type. If you place them on setters which return void, the validation engine assumes a cross parameters constraint (method validation). Moving the constraints will fix the problem.

于 2013-08-11T08:54:57.053 回答