[size=4]
- Vaadin version
[/size]
I use Vaadin version 7.1.13, but this problem is still reproduced in higher versions. For example problem also reproduced in Vaadin version 8.0.5
[size=4]
- Description of the bug
[/size]
I suppose that the explanation in the code example would be enough to understand the problem.
I met this case in real situation when I tried to extend
CustomComponent
for my needs and only one solution I found is to use
UI.getCurrent().push();
into implementation of
CustomComponent
. I don’t really like this idea and I think there could be an other way to solve this problem correctly.
[size=4]
- Reproducible example
[/size]
(Just create component using
createReproducibleExample()
method and click to
Update table content
button to see explanation
private static class Table extends VerticalLayout {
private final List<Component> headers;
private Table(final Component... headers) {
this.headers = Arrays.asList(headers);
}
private void updateContent(final Component... rows) {
removeAllComponents();
if (false) {
//In this case all works fine
for (final Component component : headers) {
addComponent(component);
}
} else {
//In case with intermediate container logic works not as it is expected
//UI.getCurrent().push(); //Uncommenting this code would solve a problem
final HorizontalLayout tableHead = new HorizontalLayout();
for (final Component component : headers) {
tableHead.addComponent(component);
}
addComponent(tableHead);
}
final VerticalLayout tableBody = new VerticalLayout();
for (final Component component : rows) {
tableBody.addComponent(component);
}
addComponent(tableBody);
}
}
private final Table table = new Table(new Label("Header 1"), new Label("Header 2"));
private Component createReproducibleExample() {
final AtomicInteger counter = new AtomicInteger(1);
return new VerticalLayout(
new Button("Update table content", event -> {
table.setEnabled(false);
UI.getCurrent().push();
//.... some actions
try { Thread.sleep(2000); } catch (InterruptedException ignore) {}
table.updateContent(new Label("Content number: " + counter.incrementAndGet()));
//.... some actions
table.setEnabled(true);
UI.getCurrent().push();
}),
table
);
}