2012-11-09 25 views
0

我正在使用GWT編輯器和javax驗證。GWT編輯器驗證HasEditorErrors始終爲空

我有一個子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.  
      } 
} 

當我打電話驗證和小部件的getValue返回null,則ConstraintViolation集合包含錯誤,但在showErrors被調用時,列表爲空。

任何想法爲什麼違規被發現,但然後沒有使它的部件showErrors?

+0

我遇到了同樣的問題。你能解決這個問題嗎? –

回答

0

這似乎是一個GWT 2.4問題。我在GWT 2.5中做了同樣的例子,並且路徑被正確設置並且錯誤集合是正確的。

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)方法特定部件的錯誤。

+0

我有這一切。違規包含錯誤,但showErrors集合爲空。另外,在這個例子中,beanA顯示錯誤,但嵌套的beanB似乎是問題。 – Kenoyer130

+0

一些更多的挖掘和問題似乎是路徑解決。該屬性的路徑是beanB.value,但simpleViolations.pushViolations中的絕對路徑是beanB.beanB.value。 – Kenoyer130

+0

對不起!我沒有使用內部綁定...不能幫你嗎:( – AmirMV