GWT 编辑器:显示约束冲突和编辑器错误



我很难实现GWT编辑器同时显示可能的ConstraintViolationEditorError。显示错误或验证冲突都没有问题。

以下示例使用Entity的某些number字段

实体.java:

....
@NotNull
private Integer number;
public Integer getNumber() {
    return number;
}
public void setNumber(Integer number) {
    this.number = number;
}
...

实体编辑器.ui.xml

...
<editor:ValueBoxEditorDecorator ui:field="number">
    <editor:valuebox>
        <g:IntegerBox />
    </editor:valuebox>
</editor:ValueBoxEditorDecorator>
...

实体编辑器.java

...
@UiField
ValueBoxEditorDecorator<Integer> number;
private Validator fValidator;
private EntityEditorDriver fEditorDriver;
...
public void validate() {
    Entity entity = fEditorDriver.flush();
    Set<ConstraintViolation<Entity>> violations = fValidator.validate(entity);
    if (!violations.isEmpty() || fEditorDriver.hasErrors()) {
        fEditorDriver.setConstraintViolations(violations);
    } else {
        // process the entity
    }
}

当我打电话给validate()而不在号码框中输入任何内容时,正确显示消息"不能为空"。使用"asdf"调用validate()我希望看到两条消息"不能为空"和"错误值(asdf)",但只显示第一个。当我不调用setConstraintViolations()时会显示编辑器错误,但显然不会显示任何验证冲突。

我错过了什么?

谢谢。

您必须

getErrors()并将它们与约束冲突合并(实现包装EditorErrorConstraintViolation

最新更新