Search code examples
windowvaadinvaadin8modal-window

Vaadin 8 the window is rolled back to the beginning when the value in the component changes


In my application, I need a pop-up window with a lot of content that does not fit completely into the browser window and has a scroll bar. I have already tried to show a pop-up window using Browser Window Opener, but ran into the following problem (enter link description here). Following the advice suggested in the comments, I changed Browser Window Opener to Window in modal mode.

The resulting main view:

enter image description here

And modal view:

enter image description here

The modal window contains 200 TextFields. At first glance, everything looks good, but if I scroll the window down and try to enter data, for example, in a field 22, then the scroll wheel is unwound to the beginning of the window:

enter image description here

The code for add window:

button.addClickListener(e -> { TestForm subForm = new TestForm();

        Window subWindow = new Window("460006801");
        subWindow.setContent(subForm);
        subWindow.center();
        subWindow.setModal(true);

        UI.getCurrent().addWindow(subWindow);
    });

TestForm:

public class TestForm extends FormLayout implements Serializable{
    public Button save = new Button("Save");

    public TestForm() {
        for(int i = 0; i < 200; i++) {
            TextField textField = new TextField("field " + i);
            addComponent(textField);
        }
    }

    public void saveConfigs() {
        System.out.print("Save ");
    }
}

What I really need is of course that when changing the value in the text box, the focus on the page stays in the same place instead of scrolling to the beginning.


Solution

  • The problem is the same as that presented by the link the problem

    The solution is to set the "height" parameter to 100%