我认为ValueBoxEditorDecorator会在文本框的右侧显示错误。我正在运行此代码。当拾取错误时,我会收到一个警告框,但ValueBoxEditorDecorator没有显示任何内容。
public class AddressEditor extends Composite implements Editor<Address>, HasEditorErrors<Address>
{
private static final Binder binder = GWT.create(Binder.class);
@UiField ValueBoxEditorDecorator<String> name;
interface Binder extends UiBinder<Widget, AddressEditor> {
}
public AddressEditor() {
initWidget(binder.createAndBindUi(this));
}
@Override
public void showErrors(List<EditorError> errors) {
name.showErrors(errors);
if (errors.size()>0)
{
StringBuilder sb = new StringBuilder();
for(EditorError e : errors)
{
sb.append(e.getMessage());
}
Window.alert(sb.toString());
}
}
这是xml ui。
<e:ValueBoxEditorDecorator ui:field="name">
<e:valuebox>
<g:TextBox/>
</e:valuebox>
</e:ValueBoxEditorDecorator>
编辑:
这是我的验证检测代码。也许我正在删除有关错误路径文件的一些数据。
a = editorDriver.flush();
ValidatorFactory factory = Validation.byDefaultProvider().configure().buildValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<Address>> violations = validator.validate(a);
@SuppressWarnings({ "unchecked", "rawtypes" })
Set<ConstraintViolation<?>> violations2 = (Set<ConstraintViolation<?>>) (Set) violations;
editorDriver.setConstraintViolations(violations2);
答案 0 :(得分:0)
找到它。问题是我的JSR303注释在私有字段上,而不是在getter上。