0

我的印象是 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 用户界面。

<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);
4

1 回答 1

0

找到了。问题是我的 JSR303 注释在私有字段上,而不是在 getter 上。

于 2013-10-14T21:25:57.140 回答