1
我很难实现GWT编辑器同时显示可能的ConstraintViolation
s和EditorError
s。显示错误或验证违规是没有问题的。GWT编辑器:显示约束违规和编辑器错误
以下示例使用一Entity
Entity.java的一些number
字段:
....
@NotNull
private Integer number;
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
...
EntityEditor.ui.xml
...
<editor:ValueBoxEditorDecorator ui:field="number">
<editor:valuebox>
<g:IntegerBox />
</editor:valuebox>
</editor:ValueBoxEditorDecorator>
...
EntityEditor.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()
我期望看到两条消息“不能为空”。和“Bad value(asdf)”,但只显示第一个。当我没有拨打setConstraintViolations()
时显示编辑器错误,但显然没有显示验证违规。
我错过了什么?
谢谢。
由于它们合并,这是我目前的解决方法。希望能有另一种解决方案。 – z00bs
我会建议提交一个改进请求,在'EditorError'中添加一个'toConstraintViolation()'方法,以简化这个过程。 –
通过http://code.google.com/p/google-web-toolkit/issues/detail?id=7809完成 – z00bs