aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/abstractfield/IntegerFieldWithoutDataSource.java
blob: 31dc2d0ce31db203cb3c0eff04e19584d162b0ac (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
package com.vaadin.tests.components.abstractfield;

import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.v7.ui.TextField;

public class IntegerFieldWithoutDataSource extends TestBase {

    private Log log = new Log(5);

    @Override
    protected void setup() {
        addComponent(log);

        TextField tf = createIntegerTextField();
        tf.setCaption(tf.getCaption() + "(invalid allowed)");
        addComponent(tf);
        tf = createIntegerTextField();
        tf.setInvalidAllowed(false);
        tf.setCaption(tf.getCaption() + "(invalid not allowed)");
        addComponent(tf);
    }

    private TextField createIntegerTextField() {
        final TextField tf = new TextField("Enter an integer");
        tf.setConverter(Integer.class);
        tf.setImmediate(true);
        tf.addValueChangeListener(event -> {
            try {
                log.log("Value for " + tf.getCaption() + " changed to "
                        + tf.getValue());
                log.log("Converted value is " + tf.getConvertedValue());
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
        });

        return tf;
    }

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

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

}