aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/table/ScrollCausesRequestLoop.java
blob: 007f3bbc2b3752d03be1b2e0114fa5b6eddd7308 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.vaadin.tests.components.table;

import java.util.ArrayList;
import java.util.List;

import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.tests.components.AbstractTestCase;
import com.vaadin.tests.util.Person;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.Table;

public class ScrollCausesRequestLoop extends AbstractTestCase {

    @Override
    public void init() {
        setMainWindow(new LegacyWindow("", new TestView()));
    }

    @Override
    protected String getDescription() {
        return "Scrolling a table causes an infinite loop of UIDL requests in some cases";
    }

    @Override
    protected Integer getTicketNumber() {
        return 8040;
    }

    private static class TestView extends HorizontalLayout {

        TestView() {
            Table table = new Table();
            List<Person> data = createData();
            BeanItemContainer<Person> container = new BeanItemContainer<Person>(
                    Person.class, data) {

                @Override
                public Person getIdByIndex(int index) {
                    try {
                        // Simulate some loading delay with some exaggeration
                        // to make easier to reproduce
                        Thread.sleep(50);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        throw new RuntimeException(e);
                    }
                    return super.getIdByIndex(index);
                }
            };
            table.setContainerDataSource(container);
            addComponent(table);
        }
    }

    private static List<Person> createData() {
        int count = 500;
        List<Person> data = new ArrayList<Person>(count);
        for (int i = 0; i < count; i++) {
            data.add(new Person("Person", "" + i, "Email", "Phone", "Street",
                    12345, "City"));
        }
        return data;
    }
}