0

我不知道为什么这不起作用。

第一的。我的行为是这样的,我将省略代码以尝试更好地解释:

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.*/

当我保存整个对象时,我会违反属性:

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

为什么?我刚刚调试了我的代码,并且 ListEditor 是同步的,我的意思是:

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

ListEditor getList() 上没有 BitacoraProxy,然后在 Save 按钮上:

 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() 上不存在的代理的约束。

任何帮助将不胜感激。

谢谢你。

4

1 回答 1

0

BitacoraProxy已被edit()编辑(至少由编辑器框架),因此它是 , 的一部分RequestContext并将被发送到服务器(它只是 ID,除非您更改了它的某些属性),因此无论是否会被验证以后用还是不用。

这是一个已知问题 (1),但它是 RequestFactory 原始设计的一部分,所以我不确定如何真正修复它。另见问题 5926


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

于 2012-04-20T09:07:25.803 回答