Grid refresh gui after edit and save item in inline editor

Hi,

I am using the newst vaadin framework 7.4.3

<vaadin.version>7.4.3</vaadin.version> In my GUI i display a Grid component.
The Datasource is a GeneratedPropertyContainer which is a wrapper over an BeanItemContainer.
The wrapper is needed to hide some

 final BeanItemContainer<Object> container = new BeanItemContainer<Object>(entityClass, queryForTableNames.getResultList());
 // Hide now internal columns
final GeneratedPropertyContainer wrapperContainer = new GeneratedPropertyContainer(container);
wrapperContainer.removeContainerProperty("internalId");
wrapperContainer.removeContainerProperty("lockedBy");

final Grid grid = new Grid(wrapperContainer);
grid.setImmediate(true);
grid.setEditorEnabled(true);
grid.setWidth("100%");
grid.setHeightByRows(22);
grid.setHeightMode(HeightMode.ROW);

The Problem is when an Item in the Grid is edited and saved with the Inline Editor, the GUI is not refreshed.

I checked in the postCommit of the FieldGroup.CommitHandler if the container is updated.
This is not true. But the Grid on the GUI does not show the change.

 grid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() {

                private Item existingContainerItem;

                @Override
                public void preCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {
                }

                @Override
                public void postCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {


                        Item editedItem = commitEvent.getFieldBinder().getItemDataSource();
...
...

Has somebody any idea to solve this problem?

Thanks

Hi,

I had the same problem, and I think I ended up fixing it just now by implementing equals() for the entities being edited by the grid, i.e. you should compare the persistent ID’s, not the pointers. (To be fully honest, I also fiddled with setBuffered(true), and I don’t really know if that changed anything in the end.)

Cheers!

Hi,

This behaviour is still on Vaadin 7.5.9, let’s see on 7.6.

I work-around this behaviour by forcing the refresh on the underlying container from the DB:

        FieldGroup fieldGroup = grid.getEditorFieldGroup();
        fieldGroup.addCommitHandler(new FieldGroup.CommitHandler() {
            @Override
            public void preCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {
                System.out.println("PreCommit");
            }

            @Override
            public void postCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {
                Item editedItem = commitEvent.getFieldBinder().getItemDataSource();
                System.out.println("PostCommit ("+editedItem+")");
                refresh();
            }
        });

and with some refresh method on your class:

public void refresh() { yourContainer.refresh(); System.out.println("Time data refreshed"); } I admit that this is a bit “brute-force approach” as it refreshes the entire container from the DB, but until this strange behaviour is fixed, this workaround worked to me.

Cheers.

I think this refresh can’t be done in post commit. Is there any other solution for this now?

I solved the problem by overriding the “saveEditor” method (in a class derived from Grid) and forcing a refresh:

    @Override
    public void saveEditor() throws FieldGroup.CommitException {
        super.saveEditor();
        refreshVisibleRows();
    }

    public void refreshVisibleRows() {
        Collection<Extension> extensions = getExtensions();
        for (Extension extension : extensions) {
            if (extension instanceof RpcDataProviderExtension) {
                ((RpcDataProviderExtension) extension).refreshCache();
            }
        }
    }

I would be very curious to understand why this is not the standard behaviour of the grid…

And I cannot unterstand, that I find the same problem still in Vaadin 8.1.7. How can it be, that the examples from Web and documentation do not work. Some time I loved Vaadin, but so elementary problem frustrate.

Wolf