From 84449d07b0e637ce16cc3d6cde2ec7113130f281 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 18 Sep 2012 16:14:21 +0300 Subject: Label.setPropertyDataSource now updates the state value (#9618) --- server/src/com/vaadin/ui/Label.java | 11 ++++++ .../components/label/LabelPropertySourceValue.html | 37 +++++++++++++++++++ .../components/label/LabelPropertySourceValue.java | 42 ++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/label/LabelPropertySourceValue.html create mode 100644 uitest/src/com/vaadin/tests/components/label/LabelPropertySourceValue.java diff --git a/server/src/com/vaadin/ui/Label.java b/server/src/com/vaadin/ui/Label.java index 8b5cd87648..bdac278b1f 100644 --- a/server/src/com/vaadin/ui/Label.java +++ b/server/src/com/vaadin/ui/Label.java @@ -170,6 +170,16 @@ public class Label extends AbstractComponent implements Property, // Use internal value if we are running without a data source return getState().text; } + return getDataSourceValue(); + } + + /** + * Returns the current value of the data source. Assumes there is a data + * source. + * + * @return + */ + private String getDataSourceValue() { return ConverterUtil.convertFromModel(getPropertyDataSource() .getValue(), String.class, getConverter(), getLocale()); } @@ -258,6 +268,7 @@ public class Label extends AbstractComponent implements Property, setConverter(c); } dataSource = newDataSource; + getState().text = getDataSourceValue(); // Listens the new data source if possible if (dataSource != null diff --git a/uitest/src/com/vaadin/tests/components/label/LabelPropertySourceValue.html b/uitest/src/com/vaadin/tests/components/label/LabelPropertySourceValue.html new file mode 100644 index 0000000000..bda4403b2b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/label/LabelPropertySourceValue.html @@ -0,0 +1,37 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/LabelPropertySourceValue?restartApplication
assertText//div[@id='runLabelPropertySourceValue-596713704']/div/div[2]/div[2]/div/div/divHello Vaadin user
clickvaadin=runLabelPropertySourceValue::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]
assertTextvaadin=runLabelPropertySourceValue::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]This text should appear on the label after clicking the button.
+ + diff --git a/uitest/src/com/vaadin/tests/components/label/LabelPropertySourceValue.java b/uitest/src/com/vaadin/tests/components/label/LabelPropertySourceValue.java new file mode 100644 index 0000000000..fdbb3caddb --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/label/LabelPropertySourceValue.java @@ -0,0 +1,42 @@ +package com.vaadin.tests.components.label; + +import com.vaadin.data.util.ObjectProperty; +import com.vaadin.server.WrappedRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; + +public class LabelPropertySourceValue extends AbstractTestUI implements + Button.ClickListener { + private Label label; + + @Override + public void setup(WrappedRequest request) { + label = new Label("Hello Vaadin user"); + Button button = new Button("Give label a new property data source..."); + button.addClickListener(this); + + addComponent(label); + addComponent(button); + } + + public void buttonClick(ClickEvent event) { + ObjectProperty p = new ObjectProperty( + "This text should appear on the label after clicking the button."); + + label.setPropertyDataSource(p); + // + } + + @Override + protected String getTestDescription() { + return "The value should change by clicking the button"; + } + + @Override + protected Integer getTicketNumber() { + return 9618; + } + +} \ No newline at end of file -- cgit v1.2.3