aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java
blob: 9bb88ddb542b5174282c0bf1a6581c32696ba2a8 (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
package com.vaadin.tests.converter;

import java.util.Locale;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.v7.ui.TextField;

public class ConverterThatEnforcesAFormat extends AbstractTestUIWithLog {

    @Override
    protected void setup(VaadinRequest request) {
        final TextField tf = new TextField(
                "This field should always be formatted with 3 digits");
        tf.setLocale(Locale.ENGLISH);
        // this is needed so that IE tests pass
        tf.setNullRepresentation("");
        tf.setConverter(new StringToDoubleConverterWithThreeFractionDigits());
        tf.addValueChangeListener(event -> {
            log("Value changed to " + event.getProperty().getValue()
                    + "(converted value is " + tf.getConvertedValue()
                    + "). Two-way conversion gives: "
                    + tf.getConverter().convertToPresentation(
                            tf.getConverter().convertToModel(tf.getValue(),
                                    Double.class, tf.getLocale()),
                            String.class, tf.getLocale())
                    + ")");
        });
        tf.setImmediate(true);
        addComponent(tf);
        tf.setConvertedValue(50.0);
    }

    @Override
    protected String getTestDescription() {
        return "Entering a valid double in the field should always cause the field contents to be formatted to contain 3 digits after the decimal point";
    }

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

}