aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/minitutorials/v7a1/IntegerTextFieldStandalone.java
blob: 88116ab3d5278558410ef5793a5b9bff4bce1b62 (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
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.util.converter.Converter.ConversionException;
import com.vaadin.v7.data.util.converter.StringToIntegerConverter;
import com.vaadin.v7.ui.TextField;

public class IntegerTextFieldStandalone extends AbstractReindeerTestUI {

    @Override
    protected void setup(VaadinRequest request) {
        final TextField textField = new TextField("Text field");
        textField.setConverter(new StringToIntegerConverter());

        Button submitButton = new Button("Submit value", new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                String uiValue = textField.getValue();
                try {
                    Integer convertedValue = (Integer) textField
                            .getConvertedValue();
                    Notification.show("UI value (String): " + uiValue
                            + "<br />Converted value (Integer): "
                            + convertedValue);
                } catch (ConversionException e) {
                    e.printStackTrace();
                    Notification.show("Could not convert value: " + uiValue);
                }
            }
        });

        addComponent(new Label("Text field type: " + textField.getType()));
        addComponent(new Label("Converterd text field type: "
                + textField.getConverter().getModelType()));
        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%20when%20not%20using%20a%20data%20source";
    }

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

}