summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Lumme <erik@vaadin.com>2017-09-15 12:34:10 +0300
committerErik Lumme <erik@vaadin.com>2017-09-15 12:34:10 +0300
commitc69d0457711d8236be2d3867671f3e7f75d481b8 (patch)
treee9f6321433d00f9791649e4447bed7ea7a996d17
parent2cd55b357b32bfa6998a7cd228f32624204132a2 (diff)
downloadvaadin-framework-c69d0457711d8236be2d3867671f3e7f75d481b8.tar.gz
vaadin-framework-c69d0457711d8236be2d3867671f3e7f75d481b8.zip
Migrate CreaingAtextFieldFOrIntegerONlyINputWhenNotUsingADtaSource
-rw-r--r--documentation/articles/CreatingATextFieldForIntegerOnlyInputWhenNotUsingADataSource.asciidoc44
-rw-r--r--documentation/articles/contents.asciidoc1
2 files changed, 45 insertions, 0 deletions
diff --git a/documentation/articles/CreatingATextFieldForIntegerOnlyInputWhenNotUsingADataSource.asciidoc b/documentation/articles/CreatingATextFieldForIntegerOnlyInputWhenNotUsingADataSource.asciidoc
new file mode 100644
index 0000000000..62c8390a07
--- /dev/null
+++ b/documentation/articles/CreatingATextFieldForIntegerOnlyInputWhenNotUsingADataSource.asciidoc
@@ -0,0 +1,44 @@
+[[creating-a-textfield-for-integer-only-input-when-not-using-a-data-source]]
+Creating a TextField for integer only input when not using a data source
+------------------------------------------------------------------------
+
+A `TextField` is a component that always has a value of type `String`. By
+adding a converter to a field, the field will automatically validate
+that the entered value can be converted and it will provide the
+converted value using the `getConvertedValue()` method.
+
+[source,java]
+....
+final TextField textField = new TextField("Text field");
+textField.setConverter(Integer.class);
+
+Button submitButton = new Button("Submit value", new ClickListener() {
+ 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) {
+ Notification.show(
+ "Could not convert value: " + uiValue);
+ }
+ }
+});
+
+addComponent(new Label("Text field type: " + textField.getType()));
+addComponent(new Label("Converted text field type: "
+ + textField.getConverter().getModelType()));
+addComponent(textField);
+addComponent(submitButton);
+....
+
+With this example, entering a number and pressing the button causes the
+value of the `TextField` to be a `String` while the converted value will be
+an `Integer` representing the same value. If e.g. a letter is entered to
+the field and the button is pressed, the validation will fail. This
+causes a notice to be displayed for the field and an exception to be
+thrown from `getConvertedValue()`.
diff --git a/documentation/articles/contents.asciidoc b/documentation/articles/contents.asciidoc
index ee08f5fb3b..cbcce095b8 100644
--- a/documentation/articles/contents.asciidoc
+++ b/documentation/articles/contents.asciidoc
@@ -23,3 +23,4 @@
- link:JMeterTesting.asciidoc[JMeter testing]
- link:AutoGeneratingAFormBasedOnABeanVaadin6StyleForm.asciidoc[Auto-generating a form based on a bean - Vaadin 6 style Form]
- link:CreatingAReusableVaadinThemeInEclipse.asciidoc[Creating a reusable Vaadin theme in Eclipse]
+- link:CreatingATextFieldForIntegerOnlyInputWhenNotUsingADataSource.asciidoc[Creating a TextField for integer only input when not using a data source]