In my project I have Company entity with an embedded Address object.
Object structure is almost the same as it is found in the DynaTableRF
example.
On the client side CompanyProxy extends EntityProxy, and AddressProxy
extends ValueProxy.
I have notice that when I create AddressProxy before CompanyProxy I get
following exception when I call editorDriver.flush().isChanged() :
Caused by: java.lang.ClassCastException:
pl.scentia.gwt.themes.showcase.shared.AddressProxyAutoBean_com_google_gwt_requestfactory_shared_impl_EntityProxyCategory_com_google_gwt_requestfactory_shared_impl_ValueProxyCategory_com_google_gwt_requestfactory_shared_impl_BaseProxyCategory$1
cannot be cast to com.google.gwt.requestfactory.shared.EntityProxy
at
com.google.gwt.requestfactory.shared.impl.AbstractRequestContext.isChanged(AbstractRequestContext.java:268)
at
pl.scentia.gwt.themes.showcase.client.activity.CompanyEditActivity.isChanged(CompanyEditActivity.java:187)
And here is the related part of the activity start which is reponsible for
creating proxies, editorDriver and so on :
CompanyRequest request = requestFactory.companyRequest();
AddressProxy address = request.create(AddressProxy.class);
CompanyProxy company = request.create(CompanyProxy.class);
company.setAddress(address);
request.persist().using(company);
editorDriver = view.createEditorDriver(eventBus,requestFactory);
editorDriver.edit(company, request);
view.setDelegate(this);
panel.setWidget(view);
But to get rid of this error all I have to do is to create the AddressProxy
after CompanyProxy :
CompanyRequest request = requestFactory.companyRequest();
*CompanyProxy company = request.create(CompanyProxy.class);
*
* AddressProxy address = request.create(AddressProxy.class);*
company.setAddress(address);
request.persist().using(company);
editorDriver = view.createEditorDriver(eventBus,requestFactory);
editorDriver.edit(company, request);
view.setDelegate(this);
panel.setWidget(view);
And now I get no exceptions anymore.
In the AbstractRequestContext#isChanged() I have found that AddressProxy is
cast to EntityProxy but it is ValueProxy of course :
public boolean isChanged() {
/*
* NB: Don't use the presence of ephemeral objects for this test.
*
* Diff the objects until one is found to be different. It's not just a
* simple flag-check because of the possibility of "unmaking" a change,
per
* the JavaDoc.
*/
for (AutoBean<?> bean : editedProxies.values()) {
AutoBean<?> previous = bean.getTag(PARENT_OBJECT);
if (previous == null) {
// Compare to empty object
*Class<?> proxyClass = ((EntityProxy)
bean.as()).stableId().getProxyClass();*
previous =
getRequestFactory().getAutoBeanFactory().create(proxyClass);
}
if (!AutoBeanUtils.diff(previous, bean).isEmpty()) {
return true;
}
}
return false;
}
So my question is the proxy creation really matters ? From the DynaTableRF
I could conclude that it is not, but in that example isChanged is not called
anywhere.
In the DynaTableRF setting the address is called after the marking parent
entity to be edited.
PersonProxy person = context.edit(context.create(PersonProxy.class));
person.setAddress(address);
When I do this the same in my application flushing the editorDriver does not
populate changes to address fields and validation against the address fields
is not called.
I've got also another problem related to checking if the proxy is changed.
In the activity mayStop I'm checking whether the proxy has been changed or
not. If yes I display confirmation box.
This is the proxy creation stage so the form is populated with the empty
text boxes and as long as the user does not enter any value into the boxes
he should be free to go to the other place without any confirmation,
but the confirmation appears because isChanged() returns true.
I guess that's because I'm setting the address instance to the company. So
the underlying requestContext believes that the company proxy has really
been changed.
I thought that it starts tracking the changes after calling the edit but it
seems that no.
Is there any way to tell the requestContext, to track changes from now ?
Or maybe I miss something and dealing with requestFactory and nested proxies
should be done in some other way ?
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.