Grid Editor Events

Hi.

I am trying to utilize the Grid.EditorListener but it seems to be not working in my case. This may be a very simple mistake so please excuse me if it is.

The Grid is required to not have buffered editing (i.e. Save Cancel buttons should not show). Moreover, the database should also be updated immediately right after an Item is edited. I am using a LazyQueryContainer which handles the db update via its’ saveItems() function. This is triggered via container.commit();

Here is a snippet from my code:

                gridQSRHeader.setImmediate(true);
                gridQSRHeader.setEditorBuffered(false); // disable Save Cancel button on Grid Editor
    
                Grid.EditorListener editorListener = new Grid.EditorListener() {
    
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void editorOpened(EditorOpenEvent e) {
                        System.out.println("Editor Opened");
                    }
                    
                    @Override
                    public void editorMoved(EditorMoveEvent e) {
                        System.out.println("Editor Moved");
                        if(lqHeaderContainer.isModified()){
                            lqHeaderContainer.commit();
                        }
                    }
                    
                    @Override
                    public void editorClosed(EditorCloseEvent e) {
                        System.out.println("Editor Closed");
                        if(lqHeaderContainer.isModified()){
                            lqHeaderContainer.commit();
                        }
                    }
                };

                gridQSRHeader.addListener(Grid.EditorOpenEvent.class, editorListener, Grid.EditorListener.EDITOR_OPEN_METHOD);
                gridQSRHeader.addListener(Grid.EditorMoveEvent.class, editorListener, Grid.EditorListener.EDITOR_MOVE_METHOD);
                gridQSRHeader.addListener(Grid.EditorCloseEvent.class, editorListener, Grid.EditorListener.EDITOR_CLOSE_METHOD);

When I run the above code the container.commit() does not happen. Even the Console has no output text.

Any help would be appreciated. Thanks!

Hi there.

I am also looking for a similar solution. Previously, during the 7.6.alpha releases, the grid had an EditorListner, not so much now. I need to know when the editor opens and closes at the very least, but knowing that it jumped rows is also very important.

On a similar note, is there a standard way to control the tabbing sequence when the editor opens? It works close to what I want, but given my grid’s strange nature, I need to be able to better control where the next tabstop is.

Thanks

Hi,

The problem with EditorListener in that case was the fact that it was not java 8 compatible. That’s why we had to drop it.

There are some ways to detect the editor moving even without it. Controlling the Grid events can be done with a client-side extension as described in my
blog post
. The event handling in the client-side is highly custom code and providing a “one solution fits all” approach is practically impossible.

About the original question about the commit not happening, it might be the order of the events is so that the editor movement is informed first and the commit from the editor to the item is done after that. You could listen to the commit event from the Editior FieldGroup instead of editor moving.

//Teemu

Hi Teemu. Thanks for the reply.

I did try the commit events of the FieldGroup before I posted here. The issue I encountered is that the preCommit() and postCommit() are NOT triggered when the Editor is in UNBUFFERED mode, which is my requirement.
Even if I put the editor into buffered mode (with Save Cancel buttons), the Container.Commit() within the postCommit() triggers an exception because the postCommit happens BEFORE the actual commit (???). I am not sure if this is correct.
Here is a snippet from Vaadin’s FieldGroup class.

public void commit() throws CommitException {
if (!isBuffered()) {
// Not using buffered mode, nothing to do
return;
}

    startTransactions();

    try {
        firePreCommitEvent();

        Map<Field<?>, InvalidValueException> invalidValueExceptions = commitFields();

        if (invalidValueExceptions.isEmpty()) {
            [color=#FF0000]

firePostCommitEvent();
[/color]

commitTransactions();

} else {
throw new FieldGroupInvalidValueException(
invalidValueExceptions);
}
} catch (Exception e) {
rollbackTransactions();
throw new CommitException(“Commit failed”, this, e);
}
}