Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EditorImpl of Grid inline Editor runs validations twice on save. #6906

Open
TatuLund opened this issue Dec 10, 2024 · 0 comments
Open

EditorImpl of Grid inline Editor runs validations twice on save. #6906

TatuLund opened this issue Dec 10, 2024 · 0 comments
Labels
DX Developer experience issue performance refactor Internal improvement vaadin-grid

Comments

@TatuLund
Copy link
Contributor

TatuLund commented Dec 10, 2024

Description

The current implementation of save() method in Grid's inline Editor is as follows (EditorImpl.java):

    @Override
    public boolean save() {
        if (isOpen() && isBuffered()) {
            getBinder().validate();
            if (getBinder().writeBeanIfValid(edited)) {
                fireSaveEvent(new EditorSaveEvent<>(this, edited));
                close();
                return true;
            }
        }
        return false;
    }

The getBinder().validate() call is there apparently for the possible case that Grid has fetched data with invalid properties. This is valid scenario in some applications. The side effect of this is that validations are run twice as both validate() and writeBeanIfValid(..) runs the validations. This is a problem if the validators are heavy, e.g. having backend calls.

I would recommend to remove the getBinder().validate() and instead add documentation for developer to call it explicitly in the application code if needed by business logic of the application. In many cases it would be better to call it already when editor opens and not at save stage.

Alternatively there could be additional API to configure whether additional pre-validation is being performed or not and let it be default in order to avoid breaking change.

Expected outcome

Validators not being run twice.

Minimal reproducible example

Trivial.

Steps to reproduce

Trivial.

Environment

Vaadin version(s): latest 14, 23, 24 versions.

Browsers

No response

@yuriy-fix yuriy-fix added vaadin-grid DX Developer experience issue performance refactor Internal improvement labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Developer experience issue performance refactor Internal improvement vaadin-grid
Projects
None yet
Development

No branches or pull requests

2 participants