Nick Siderakis
Nick Siderakis

Reputation: 1961

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(
            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.

Upvotes: 0

Views: 2003

Answers (1)

fabiangebert
fabiangebert

Reputation: 2623

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))

Upvotes: 1

Related Questions