0

我正在使用 GWT 编辑器和 javax 验证。

我有一个带有像这样的子 bean 的模型 bean ->

public interface BeanA {

    @Valid
    BeanB getBeanB();

    void setBeanB(BeanB b);
}

public interface BeanB {

    @NotEmpty
    public String getValue();

    public void setValue(String value);

}

有一个实现 LeafValueEditor、HasEditorErrors 接口的 Widget。

该值似乎毫无问题地具有约束力。

    public class MyWidget extends Composite implements 
                                 LeafValueEditor<String>, HasEditorErrors<String>{
    ...

    @Override
    public void showErrors(List<EditorError> errors) {
           // Even though the error is flagged 
           // the errors collection does not contain it.    
           }
}

当我调用 validate 并且小部件 getValue 返回 null 时,ConstraintViolation 集合包含错误,但是当调用 showErrors 时,List 为空。

知道为什么发现违规但没有出现在小部件 showErrors 中吗?

4

2 回答 2

0

如果您使用 GWT 编辑器,您将拥有SimpleBeanEditorDriver由 GWT.create(...) 创建的界面。这个接口有一个方法setConstraintViolations(violations)可以让你违反约束。当您验证您的模型时,您会遇到Set<ConstraintViolation<E>>违规行为,然后您会将其传递给您的编辑器驱动程序。例如

Set<ConstraintViolation<E>> violations = getValidator().validate(model,
            groups);
getEditorDriver().setConstraintViolations(violations)

在此之后,您将在小部件的showErrors(List<EditorError> errors)方法上收到特定于小部件的错误。

于 2012-11-10T09:46:21.527 回答
0

这似乎是 GWT 2.4 问题。我在 GWT 2.5 中做了同样的例子,路径设置正确,错误收集正确。

于 2012-11-11T19:38:54.940 回答