I have a Grid that I create once, then setItems multiple times. The grid had styling added and after a couple of setItems, the grid blows up and all styling is removed and no data is displayed. I haven’t been able to track it down to a single cause. Has anyone experienced this?
suggestedItems = new ArrayList<Item>();
suggestionGrid = new SuggestionGrid();
...
private class SuggestionGrid extends Grid<Item> {
public SuggestionGrid() {
addStyleName(MyTheme.POSITION_ABSOLUTE);
addStyleName(MyTheme.Z_INDEX_1000);
addStyleName(MyTheme.MARGIN_TOP);
}
...
}
private void updateSuggestions(List<Item> suggestedItems){
suggestionGrid.setItems(suggestedItems);
}
private void hideSuggestions() {
suggestedItems.clear();
suggestionGrid.setItems(suggestedItems);
suggestionGrid.setVisible(false);
}
Starting to do some debugging and added some logging. Apparently the server-side component thinks it has the styles set, however the client does not.
logger.warn("Before set items: " + suggestionGrid.getStyleName());
...
logger - Before set items: position-absolute z-index-1000 margin-top
logger - After set items: position-absolute z-index-1000 margin-top
Rendered HTML
[code]
[/code]Grid contains data/rows
Typed more letters into search:
logger - Before set items: position-absolute z-index-1000 margin-top
logger - After set items: position-absolute z-index-1000 margin-top
Rendered HTML
[code]
[/code]Grid no longer contains data/rows, even though data source has items
Typed more letters into search:
logger - Before set items: position-absolute z-index-1000 margin-top
logger - After set items: position-absolute z-index-1000 margin-top
Rendered HTML
[code]
[/code]Grid no longer contains data/rows, even though data source has items
Update:
Actual log files show something might be happening while in a thread. The ui does not blow up until the last two print ‘http-nio-8080-exec-52’
2017-09-05/04:32:04.666/GMT [Thread-154]
WARN my.app.SuggestComponent - After set items: position-absolute z-index-1000 margin-top
2017-09-05/04:32:05.721/GMT [Thread-155]
WARN my.app.SuggestComponent - Before set items: position-absolute z-index-1000 margin-top
2017-09-05/04:32:05.722/GMT [Thread-155]
WARN my.app.SuggestComponent - After set items: position-absolute z-index-1000 margin-top
2017-09-05/04:32:05.723/GMT [Thread-155]
WARN my.app.SuggestComponent - Before set items: position-absolute z-index-1000 margin-top
2017-09-05/04:32:05.723/GMT [Thread-155]
WARN my.app.SuggestComponent - After set height: position-absolute z-index-1000 margin-top
2017-09-05/04:32:05.723/GMT [Thread-155]
WARN my.app.SuggestComponent - Before set items: position-absolute z-index-1000 margin-top
2017-09-05/04:32:07.289/GMT [http-nio-8080-exec-52]
WARN my.app.SuggestComponent - Before set items: position-absolute z-index-1000 margin-top
2017-09-05/04:32:07.290/GMT [http-nio-8080-exec-52]
WARN my.app.SuggestComponent - Before set items: position-absolute z-index-1000 margin-top
For the start of each thread, I get the UI
UI ui = UI.getCurrent();
new SuggestThread(searchText, ui).start();
(I also tried getUI()). Then the thread updates the UI using
I have confirmed this issue exists in versions 8.1.2, 8.1.1, 8.1.0.
The issue is not present in 8.0.6 ← this was the last 8.0.x version I was using before updating to 8.1.1
Just for fun (midight in PST), I will update to 8.1.3 to see if I can reproduce there too.
Edit: issue can be reproduced in 8.1.3
so I’ve tracked it down to a setVisible on the grid while in a thread. The only work-around for me was to not use setVisible when hiding the grid, but instead add and remove a style ‘hidden’. The css woulbe be the following:
.hidden {
visibility:hidden;
}
fyi, display:none messed with the height of the component and it was alway just a few pixels.
I’m not sure if this applies directly, but at least Vaadin 7 Grid used to not like swapping data sources many times. Have you tried updating the DataProvider instead of overriding the items in the Grid? You can either create a ListDataProvider explicitly or cast the default provider (created by setItems) to ListDataProvider.
What I can tell you is that it does not happen immediately, but only after the 3rd or so update. It varies so it looks like some timing / updated issue while in a thread. If I do not toggle the visiblity, keep visible, then the it works. Only when the visibility is toggled is when the issue happens.
I will try to put together a simple test case based on my code.