So "
equipment.name" is never updated in the proxy instance. Also I launched the following tests.
1. If I do not modify anything, dirty is always false.
2. If I modify just equipment name, dirty es true, but not updated.
3. I add new element to the list,code not here, and the new element is added correctly and persisted in the server.
I do one more test. Change RequestFactoryEditorDriver to SimpleBeanEditorDriver. And the log show that the proxy,now simple JavaBean object, is updated correctly.
PreFlush {profile=name, equip=hat, dirty=true}
PostFlush {profile=other name, equip=other type, dirty=true}
Why ListEditor doesn't update the proxy instance when using RequestFactoryEditorDriver? Thanks.
RequestFactoryEditorDriver Version
public class ProfileEditor extends Composite implements Editor<ProfileProxy> {
/** Class capable of creating and destroying instances of EquipmentEditor */
private class EquipmentEditorSource extends EditorSource<EquipmentEditor> {
public EquipmentEditor create(int index) {
EquipmentEditor editor = new EquipmentEditor();
equipmentContainer.insert(editor, index);
return editor;
}
public void dispose(EquipmentEditor subEditor) {
subEditor.removeFromParent();
}
public void setIndex(EquipmentEditor editor, int index) {
equipmentContainer.insert(editor, index);
}
}
/* UiBinder */
static ThisUiBinder uiBinder = GWT.create(ThisUiBinder.class);
interface ThisUiBinder extends UiBinder<Widget, ProfileEditor> { }
/* Editor driver */
interface Driver extends RequestFactoryEditorDriver<ProfileProxy, ProfileEditor> { }
final Driver driver = GWT.create(Driver.class);
@UiField ValueBoxEditorDecorator<String> name;
@UiField FlowPanel equipmentContainer;
ListEditor<EquipmentProxy, EquipmentEditor> equipmentListEditor
= ListEditor.of(new EquipmentEditorSource());
AppRequestFactory requestFactory;
ProfileProxy proxyBeingEdited;
public ProfileEditor(ClientFactory clientFactory) {
requestFactory = clientFactory.getRequestFactory();
initWidget(uiBinder.createAndBindUi(this));
driver.initialize(this);
fetchProxy(); // through requestFactory
}
void fetchProxy() {
requestFactory.profileRequest().getCurrentUserProfile()
.with(driver.getPaths())
.to(new Receiver<ProfileProxy>() {
public void onSuccess(ProfileProxy currentUser) {
startEdit(currentUser);
}
}).fire();
}
private void startEdit(ProfileProxy proxy) {
ProfileRequest editContext = requestFactory.profileRequest();
// Not necesary, but usefull to see if something happen!
proxyBeingEdited = editContext.edit(proxy);
driver.edit(proxyBeingEdited, editContext);
// Changes saved here --^
editContext.persist().using(proxyBeingEdited);
}
@UiHandler("save")
void onSave(ClickEvent event) {
ProfileProxy o = proxyBeingEdited;
GWT.log("PreFlush {profile=" + o.getName() + ", equip="
+ o.getEquipmentList().get(0).getType() + ", dirty="
+ driver.isDirty() + "}"); // PRELOG!!
RequestContext editedContext = driver.flush();
GWT.log("PostFlush {profile=" + o.getName() + ", equip="
+ o.getEquipmentList().get(0).getType() + ", dirty="
+ driver.isDirty() + "}"); // POSTLOG!!
// Send the request
editedContext.fire(new Receiver<Void>() {
public void onSuccess(Void response) {
startEdit(proxyBeingEdited); // Critical if you want re-save!
}
});
}
}public class EquipmentEditor extends Composite implements Editor<EquipmentProxy> {
/* UiBinder */
private static ThisUiBinder uiBinder = GWT.create(ThisUiBinder.class);
interface ThisUiBinder extends UiBinder<Widget, EquipmentEditor> { }
@UiField TextBox type;
public EquipmentEditor() { initWidget(uiBinder.createAndBindUi(this)); }
}
SimpleBeanEditorDriver Version
public class ProfileEditor extends Composite implements Editor<ProfileProxy> {
/** Class capable of creating and destroying instances of EquipmentEditor */
private class EquipmentEditorSource extends EditorSource<EquipmentEditor> {...
/* UiBinder */
static ThisUiBinder uiBinder = GWT.create(ThisUiBinder.class);
interface ThisUiBinder extends UiBinder<Widget, ProfileEditor> { }
/* Editor driver */
interface Driver extends SimpleBeanEditorDriver<ProfileProxy, ProfileEditor> { }
final Driver driver = GWT.create(Driver.class);
@UiField ValueBoxEditorDecorator<String> name;
@UiField FlowPanel equipmentContainer;
ListEditor<EquipmentProxy, EquipmentEditor> equipmentListEditor
= ListEditor.of(new EquipmentEditorSource());
AppRequestFactory requestFactory;
ProfileProxy proxyBeingEdited;
public ProfileEditor(ClientFactory clientFactory) {
requestFactory = clientFactory.getRequestFactory();
initWidget(uiBinder.createAndBindUi(this));
driver.initialize(this);
startEdit(createProxy());
}
private void startEdit(ProfileProxy proxy) { proxyBeingEdited = proxy;
driver.edit(proxyBeingEdited);
}
@UiHandler("save")
void onSave(ClickEvent event) {
ProfileProxy o = proxyBeingEdited;
GWT.log("PreFlush {profile=" + o.getName() + ", equip="
+ o.getEquipmentList().get(0).getType() + ", dirty="
+ driver.isDirty() + "}"); // PRELOG!!
driver.flush();
GWT.log("PostFlush {profile=" + o.getName() + ", equip="
+ o.getEquipmentList().get(0).getType() + ", dirty="
+ driver.isDirty() + "}"); // POSTLOG!!
}
ProfileProxy create(){ ProfileProxy object = new ProfileProxy(){
String profileName; List<EquipmentProxy> eList;
public EntityProxyId<?> stableId() { return null; }
public String getUserId() { return null; }
public String getNick() { return null; }
public void setNick(String nick) { }
public String getName() { return profileName; }
public void setName(String name) { profileName = name; }
public List<EquipmentProxy> getEquipmentList() { return eList; }
public void setEquipmentList(List<EquipmentProxy> equipmentList) { eList = equipmentList; }
};
object.setName("Bean Name");
EquipmentProxy equipment = new EquipmentProxy() {
String eType;
public EntityProxyId<?> stableId() { return null; }
public void setYear(Integer year) { }
public void setType(String type) { eType = type; }
public void setSize(Integer size) { }
public void setModel(String model) { }
public void setComment(String comment) { }
public void setBrand(String brand) { }
public Integer getYear() { return null; }
public String getType() { return eType; }
public Integer getSize() { return null; }
public String getModel() {return null; }
public Long getId() { return null; }
public Date getDueDate() { return null; }
public String getDescription() { return null; }
public String getComment() { return null; }
public String getBrand() { return null; }
};
equipment.setType("Bean Type");
object.setEquipmentList(new ArrayList<EquipmentProxy>(Arrays.asList(equipment)));
return object;
}
}