aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/minitutorials/v7a1/IntegerTextFieldDataSource.java
blob: 6bd9f7aae74efbe1ccc05abacc9364c558719f7f (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
66
67
68
69
package com.vaadin.tests.minitutorials.v7a1;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.v7.data.Property;
import com.vaadin.v7.data.util.BeanItem;
import com.vaadin.v7.ui.TextField;

public class IntegerTextFieldDataSource extends AbstractReindeerTestUI {

    public class MyBean {
        private int value;

        public int getValue() {
            return value;
        }

        public void setValue(int integer) {
            value = integer;
        }
    }

    @Override
    protected void setup(VaadinRequest request) {
        final MyBean myBean = new MyBean();
        BeanItem<MyBean> beanItem = new BeanItem<>(myBean);

        final Property<Integer> integerProperty = beanItem
                .getItemProperty("value");
        final TextField textField = new TextField("Text field",
                integerProperty);

        Button submitButton = new Button("Submit value", new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                String uiValue = textField.getValue();
                Integer propertyValue = integerProperty.getValue();
                int dataModelValue = myBean.getValue();

                Notification.show("UI value (String): " + uiValue
                        + "\nProperty value (Integer): " + propertyValue
                        + "\nData model value (int): " + dataModelValue);
            }
        });

        addComponent(new Label("Text field type: " + textField.getType()));
        addComponent(
                new Label("Text field type: " + integerProperty.getType()));
        addComponent(textField);
        addComponent(submitButton);
    }

    @Override
    protected String getTestDescription() {
        return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20TextField%20for%20Integer%20only%20input%20using%20a%20data%20source";
    }

    @Override
    protected Integer getTicketNumber() {
        // TODO Auto-generated method stub
        return null;
    }

}