【问题标题】:GWT Editor Validation HasEditorErrors is always emptyGWT 编辑器验证 HasEditorErrors 始终为空
【发布时间】:2012-11-09 21:14:25
【问题描述】:

我正在使用 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);

}

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

该值似乎没有问题。

    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 中吗?

【问题讨论】:

  • 我遇到了同样的问题。你能解决这个问题吗?

标签: validation gwt


【解决方案1】:

如果您使用 GWT 编辑器,您将拥有由 GWT.create(...) 创建的SimpleBeanEditorDriver 接口。这个接口有一个方法setConstraintViolations(violations) 从你那里得到你的约束违规。当您验证您的模型时,您会将Set&lt;ConstraintViolation&lt;E&gt;&gt; 视为违规,然后您会将其传递给您的编辑器驱动程序。例如

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

在此之后,您会在小部件的 showErrors(List&lt;EditorError&gt; errors) 方法上收到特定于小部件的错误。

【讨论】:

  • 这一切我都有。违规包含错误,但 showErrors 集合为空。此外,在示例中 beanA 显示错误很好,但嵌套 beanB 似乎是问题。
  • 更多挖掘,问题似乎是路径解析。属性的路径是 beanB.value,但 simpleViolations.pushViolations 中的绝对路径是 beanB.beanB.value。
  • 对不起!我没有使用内部绑定...无法帮助您:(
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 2013-08-18
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2020-11-22
    相关资源
    最近更新 更多