> > 2. User may add/edit/remove phones, so I wrote my own editor...
> The second step is not required; it entirely depends how persisting the
> ContactProxy works (whether it would persist a new Phone or the Phone has to
> be persisted on its own).
C'est bon :) I want Phones to be persisted by edit activity for
ContactProxy... cause I'm trying to implement following use cases:
1. User edit fields of ContactProxy...
2. User edit list of PhoneProxy for current ContactProxy... It means
he's able to add/remove/edit phones...
3. User click 'Save' and all changes persisting in DB.
It means I want 'Save' to be like a transaction... I defenitely don't
want to persist phones on it's own.
Here is some code.
I have ContactProxy{
some_fields
List<PhoneProxy> phoneList;
}
Also have an edit activity & edit view for ContactProxy.
ContactView{
some_contact_proxy_fields
PhoneListEditor phoneListEditor;
Button saveBtn;
}
ListEditor seems to provide a good boilerplate code to manage UI of
list items, so, I've implemented PhoneListEditor on the base of
ListEditor.
PhoneListEditor implements ValueAwareEditor<List<PhoneNumProxy>>,
LeafValueEditor<List<PhoneNumProxy>>{
VerticalPanel container = new VerticalPanel();
public interface Driver extends
RequestFactoryEditorDriver<List<PhoneProxy>, ListEditor<PhoneProxy,
PhoneEditView>> {}
private ListEditor<PhoneProxy, PhoneEditView> listEditor;
private List<PhoneNumProxy> displayedList;
PhoneListEditor(){
initWidget(container);
listEditor= ListEditor.of(new PhoneEditorSource());
driver = GWT.<Driver> create(Driver.class);
driver.initialize(eventBus, factory, listEditor);
driver.display(new ArrayList<PhoneProxy>());
displayedList=listEditor.getList();
}
public void addClicked() {
PhoneRequest rq=factory.phoneRequest();
PhoneProxy proxy=rq.create(PhoneProxy.class);
rq.persist().using(proxy);
displayedList.add(proxy);
}
public List<PhoneNumProxy> getValue() {
return new ArrayList<PhoneProxy>(displayedList);
}
public void setValue(List<PhoneNumProxy> value) {
for (PhoneNumProxy itemValue : value) {
displayedList.add(itemValue);
}
}
public void flush() {
driver.flush();
}
}
It seems to work ok when I start edit activity... I'm creating editor
driver for ContactProxy, editing proxy with save request...
editorDriver = view.createEditorDriver();
editorDriver.edit(getProxy(), createSaveRequest(getProxy()));
... so, all Contact data & list of phones displayed properly...
The problem occured when I try to save a new phone... I see what
flush() in AbstractRequestFactory called twice... One time for
ContactProxy & second - for PhoneProxy... For PhoneProxy I've got a
"java.lang.Throwable: edit() was called with a null Request" which is
true... for ContactProxy I'm callind edit(...) manually with my own
save request, but for PhoneProxy I don't now how to do that as edit()
should be called by RFED, right?
I'm planning to implement all those bells & whistles with validation
later... so I'm trying to use RFED... but, HOW TO MAKE IT WORK for my
case?! :) I spent a lot of time & really stuck on it... cause it seems
I didn't get something important about editor framework...
> Depending on your technical constraints (see above), you have 2 solutions:
>
> - *enqueue* a persist() call of the created proxy on the request context
> so that when you fire() it in response to the "save" button being clicked,
> you'll persist() all created proxies and the ContactProxy.
> - on the server-side, make sure the Phone instances from the Contact's
> phones list are correctly persisted: updated or created if needed.
How to *enqueue* a persist() call?
> But it all depends on how your server-side code works, and what it's able to
> do.
At back-end I have simple persist methods with one line like that:
'this.entityManager.persist(this);' :)