diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2016-07-13 14:32:03 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2016-08-05 10:19:44 +0300 |
commit | 5b7d159969b9f5e4cea45a17f4ed371afa241bb8 (patch) | |
tree | bb0c97de4a2a95593c778ba9b2e98b3076a576b1 /documentation | |
parent | 05d5160ce558dc6f18e1bb96f1ba0679e0a283d1 (diff) | |
download | vaadin-framework-5b7d159969b9f5e4cea45a17f4ed371afa241bb8.tar.gz vaadin-framework-5b7d159969b9f5e4cea45a17f4ed371afa241bb8.zip |
Vaadin 8 example code changes: Server-Side Components - Common Component Features
Change-Id: Ibdf8fa97cdc4cb9f65c83ea01bb8d6c26dcb2ade
Diffstat (limited to 'documentation')
-rw-r--r-- | documentation/components/components-features.asciidoc | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/documentation/components/components-features.asciidoc b/documentation/components/components-features.asciidoc index 625d9b8820..af15d8e250 100644 --- a/documentation/components/components-features.asciidoc +++ b/documentation/components/components-features.asciidoc @@ -377,45 +377,37 @@ final Locale[] locales = Locale.getAvailableLocales(); // language of the application can not be done before // this (and the selection) component are attached to // the application. -final ComboBox select = new ComboBox("Select a language") { +ComboBox<Locale> select = new ComboBox<>("Select a language") { @Override public void attach() { super.attach(); setValue(getLocale()); } }; -for (int i=0; i<locales.length; i++) { - select.addItem(locales[i]); - select.setItemCaption(locales[i], - locales[i].getDisplayName(displayLocale)); - - // Automatically select the current locale - if (locales[i].equals(getLocale())) - select.setValue(locales[i]); -} + +select.setItems(Arrays.asList(locales)); +select.setCaptionGenerator(locale -> locale.getDisplayName(displayLocale)); +select.setValue(getLocale()); + layout.addComponent(select); // Locale code of the selected locale -final Label localeCode = new Label(""); +Label localeCode = new Label(""); layout.addComponent(localeCode); // A date field which language the selection will change -final InlineDateField date = +InlineDateField date = new InlineDateField("Calendar in the selected language"); date.setResolution(Resolution.DAY); layout.addComponent(date); // Handle language selection -select.addValueChangeListener(new Property.ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - Locale locale = (Locale) select.getValue(); - date.setLocale(locale); - localeCode.setValue("Locale code: " + - locale.getLanguage() + "_" + - locale.getCountry()); - } +select.onValueChange(locale -> { + date.setLocale(locale); + localeCode.setValue("Locale code: " + + locale.getLanguage() + "_" + + locale.getCountry()); }); -select.setImmediate(true); ---- See the http://demo.vaadin.com/book-examples-vaadin7/book#component.features.locale.selection[on-line example, window="_blank"]. @@ -472,18 +464,14 @@ Client-side state modifications will not be communicated to the server-side and, more importantly, server-side field components will not accept changes to the value of a read-only [classname]#Field# component. The latter is an important security feature, because a malicious user can not fabricate state changes in a -read-only field. This is handled at the level of [classname]#AbstractField# in -[methodname]#setValue()#, so you can not change the value programmatically -either. Calling [methodname]#setValue()# on a read-only field results in -[classname]#Property.ReadOnlyException#. - -Also notice that while the read-only status applies automatically to the -property value of a field, it does not apply to other component variables. A -read-only component can accept some other variable changes from the client-side +read-only field. + +Also notice that while the read-only status applies automatically to the value +of a field, it does not apply to other component variables. A +read-only component can accept some other state changes from the client-side and some of such changes could be acceptable, such as change in the scroll bar -position of a [classname]#Table#. Custom widgets should check the read-only -state for variables bound to business -data. +position of a [classname]#Table#. Custom components should check the read-only +state for variables bound to business data. //// TODO: Note this also in the Advanced: Security section. @@ -691,7 +679,8 @@ component allows inputting text, the focus and insertion point are indicated by a cursor. Pressing the Tab key moves the focus to the component next in the __focus order__. -Focusing is supported by all [classname]#Field# components and also by the [classname]#Upload# component. +Focusing is supported by all [classname]#Field# and [classname]#Select# components and also by +components such as [classname]#Button#, [classname]#Upload#, and [classname]#TabSheet#. The focus order or __tab index__ of a component is defined as a positive integer value, which you can set with [methodname]#setTabIndex()# and get with |