0

I found out a strange behavior of the grid component. I have app with multiple tabs in each tab can be multiple grids, sometimes i handle some errors by showing dialog in addColumn method. I found out that every created grid are refreshing each time i change UI (by navigating or F5) I have PreserveOnRefresh annotation. So even grids from other tabs that are not visible right now are refreshing and showing me again some dialogs that are implemented in addColumn method in another grid. I have application where users can add new tabs with a lots of grids so after some time they are refreshing a lot of data after each navigation or F5 pressing. Below I'm adding code example:

    @Route("test")
@PreserveOnRefresh
public class Test extends Div {
    public Test(){

        Grid<String> grid1 = new Grid();
        List<String> grid1List = new ArrayList<>();
        grid1List.add("grid1Element");
        grid1.setItems(grid1List);
        grid1.addComponentColumn(item -> {
            Dialog grid1D = new Dialog(new SpanTrans("Grid1 Dialog"));
            grid1D.open();
            return new SpanTrans(item);
        });

        Grid<String> grid2 = new Grid();
        List<String> grid2List = new ArrayList<>();
        grid2List.add("grid2Element");
        grid2.setItems(grid2List);
        grid2.addComponentColumn(item -> {
            Dialog grid2D = new Dialog(new SpanTrans("Grid2 Dialog"));
            grid2D.open();
            return new SpanTrans(item);
        });
        TabSheet tabs = new TabSheet();
        tabs.add("Grid1",grid1);
        tabs.add("Grid2",grid2);

        add(tabs);
    }
}

So when i every time i enter each tab the dialog for grid inside this tab is shown. Why isi t hapenning every time shouldnt it be only for the first time until i'm send refresh request from my code if i would like to? And after F5/Refreshing Page both dialogs for both tabs are shown.

I want to refresh grids only when i'm executing refresh from code and not doing it for every created grid whenever UI will change. I'm using Vaadin 23.3.15

  • The event that triggers the dialogs could be triggered by either paint() repaint() update() or a more deliberate implementation of "event" such as "focus" , component layer level change , a mouse click event , or a click added to an actionevent. – Samuel Marchant Jul 21 '23 at 10:42
  • I checked in debug that for my example each time is fired action from ValueProvider in addComponentColumn – Miłosz Bąbliński Jul 21 '23 at 10:56
  • When you add columns, then the grid must recalculate col width and content, so it has to repaint. Usually you add all columns first and then bind the data to the grid – André Schild Jul 22 '23 at 19:49
  • but im not doing anything with other grids after they are created, i'm just refreshing page by F5 o routing to another page and then every previously created grid that are not even visible at this moment are refreshing like in my example. If i'm in tab "Grid2" and i press F5 then both ValueProviders( Grid1 and Grid2) are fired even that tab with Grid1 isnet even shown right now – Miłosz Bąbliński Jul 24 '23 at 09:47

0 Answers0