我正在使用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吗?
答案 0 :(得分:0)
如果你正在使用GWT编辑器,你将有GWT.create(...)创建的SimpleBeanEditorDriver
接口。此接口有一个方法setConstraintViolations(violations)
,可以从您那里获取约束。当您验证模型时,您会将Set<ConstraintViolation<E>>
视为违规,然后您将其传递给编辑器驱动程序。例如
Set<ConstraintViolation<E>> violations = getValidator().validate(model,
groups);
getEditorDriver().setConstraintViolations(violations)
在此之后,您将在窗口小部件的showErrors(List<EditorError> errors)
方法上获得特定于窗口小部件的错误。
答案 1 :(得分:0)
这似乎是一个GWT 2.4问题。我在GWT 2.5中做了相同的例子,路径设置正确,错误集合正确。