2012-04-20 93 views
0

我不知道爲什麼這不起作用。GWT編輯器框架ListEditor

首先。我的行爲是這樣,我會忽略代碼,試圖更好地解釋:

public class ProgramaEditor extends Composite implements Editor<ProgramaProxy> { 
    /*edits a ProgramaProxy just fine*/   
    /* a EditorList to edit BitacoraProxy */ 
    @UiField BitacoraListEditor bitacoras; 

} 

    public class BitacoraListEditor extends Composite implements IsEditor<ListEditor<BitacoraProxy, BitacoraEditor>>, HasRequestContext<List<BitacoraProxy>>{ 
/* edit a list of BitacoraProxy just fine */ 
protected class BitacoraEditorSource extends EditorSource<BitacoraEditor>{ 
     /* the editor source that vends Editors of BitacoraProxy*/ 
     public BitacoraEditor create(int index) { 
       final BitacoraEditor editor = new BitacoraEditor(); 
         editor.setIndex(index); 

       /*more code*/ 

         editor.addDeleteEditorHanlder(new EditorDeleteHandler() { 
         /* ... handler to remove a Editor from the list */ 
         subeditors.getList().remove(event.getIndex()); 
         } 
     } 
    } 

private ListEditor<BitacoraProxy, BitacoraEditor> subeditors = ListEditor.of(new BitacoraEditorSource()); 
} 

在服務器端:

@Entity 
public class Bitacora extends EntityBase { 
    @NotNull(message="La fecha no puede ser nulo") 
    private Date fecha;  
} 

所以一切運作良好的正常工作流程編輯ProgramaProxy再加入BitacoraProxys和然後保存,我可以使用ListEditor保存ProgramaProxy和它的@OneToMany BitacoraProxy。

問題是,當我從EditorList與刪除BitacoraProxy:

subeditors.getList().remove(event.getIndex()); 
    /*Please note the @NotNull on the Many side on the property fecha.*/ 

當我保存整個對象,我得到constrait侵犯財產:

@NotNull(message="La fecha no puede ser nulo") 
    private Date fecha; 

爲什麼?我只是debugued我的代碼和ListEditor其同步我的意思是:

Add a BitacoraProxy -> ListEditor.getList() - size = 1 
Then I remove a BitacoraProxy from the ListEditor.getList() - size = 0 

沒有BitacoraProxy在ListEditor的GetList(),然後保存按鈕:

driver.flush().fire(new Receiver<Void>() { 
      @Override 
      public void onSuccess(Void response) { 

      } 
      @Override 
      public void onConstraintViolation(Set<ConstraintViolation<?>> violations) { 
       DialogHandler handler = DialogHandler.getInstance(); 
       ErrorDialog errDlg = handler.createErrorDialog();    

       for(ConstraintViolation<?> violation:violations){ 
        errDlg.addDetail(violation.getMessage()); 
       } 
       /* more code */ 
     }); 

爲什麼我'歌廳違反約束在ListEditor.getList()中不存在的Proxys。

任何幫助將是apreciated。

謝謝。

回答

0

BitacoraProxy一直edit()版(由編輯器框架至少),因此它的RequestContext的一部分,因此,將被髮送到服務器(只有它的ID,除非你改變了它的一些屬性的),並且將將被驗證,是否將在以後使用。

這是一個已知問題(1),但它是原始設計的RequestFactory的一部分,所以我不知道如何真正修復它。另見issue 5926


(1)見http://gwt-code-reviews.appspot.com/1601806/diff/9001/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java#newcode1182

+0

喜托馬斯TODO,感謝您的回答。在ListEditor(CompositeEditor)上從列表中移除時,可能需要有一些信息告訴RequestContext移除該EntityProxy ?.我剛剛刪除了@NotNull,然後在客戶端驗證我的字段。 – 2012-04-20 16:48:34