2012-04-20 104 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