我不知道为什么这不起作用。
第一的。我的行为是这样的,我将省略代码以尝试更好地解释:
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() 上不存在的代理的约束。
任何帮助将不胜感激。
谢谢你。