How to edit List items in GWT CellTable using an Editor with Driver and RequestFactory
The following snippet displays the list of Cats successfully, however when I flush the driver the values in the Cat objects are all null.
The name of the cat house can be edited as expected.
HasDataEditor<CatProxy> residentsEditor= HasDataEditor.of(cellTable)
CatHouse{
String name;
List<Cat> residents;
}
Cat{
String name;
String favoriteColor;
}
Here is how I am creating the request. (Adapted from the MobileWebApp sample project)
// Flush the changes into the editable CatHouse.
final CatHouseRequest context = (CatHouseRequest) clientFactory.getCatHouseEditView().getEditorDriver().flush();
/*
* Create a persist request the first time we try to save this task. If
* a request already exists, reuse it.
*/
if (taskPersistRequest == null) {
taskPersistRequest = context.updateCatHouse(editTask).with(
开发者_如何学Python clientFactory.getCatHouseEditView().getEditorDriver().getPaths());
}
// Fire the request.
taskPersistRequest.fire(new Receiver<ActionProxy>() {
@Override public void onConstraintViolation(final Set<ConstraintViolation<?>> violations) {
...
}
@Override public void onSuccess(final CatHouseProxy response) {
...
}
});
I've inspected the taskPersistRequest variable right before it was fired.
taskPersistRequest.propertyRefs = [catHouse]
taskPersistRequest.requestContext has the correct values for the CatHouse and the Cats.
taskPersistRequest.requestData.parameters only has one value for CatHouse with no data related to Cats. (This looks like the problem)
The editProxies variable in context has the correct values for the CatHouse and Cat.
I ran into a similar problem today. If you create the CatHouse before the Cat items are created, on the same RequestContext, persisting the CatHouse will fail, because the Cat items are not available yet.
To fix this: create the Cat beans first and create the CatHouse beans afterwards:
cat = request.create(Cat.class)
catHouse = request.create(CatHouse.class)
Implementing this when using the editor framework is not trivial, however, since it requires you to pass an instance of CatHouse in the editor driver before the editor will trigger the creation of the Cat instances.
A possible workaround is to copy the flushed auto bean on a new request context in a way that the Cats are created before the CatHouse is.
(In case you're not creating, but simply editing the cat house, think in terms of request.edit(catHouse) rather than request.create(CatHouse.class))
精彩评论