我很难实现 GWT 编辑器同时显示可能ConstraintViolation
的 s 和EditorError
s 。显示错误或验证违规都没有问题。
以下示例使用某个number
字段Entity
实体.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()
但显然不会显示验证违规。
我错过了什么?
谢谢你。