diff options
author | Matti Hosio <mhosio@vaadin.com> | 2014-12-11 09:05:19 +0200 |
---|---|---|
committer | Matti Hosio <mhosio@vaadin.com> | 2014-12-12 09:49:00 +0200 |
commit | 64a029571955ee52b0c416b597fb718bc0a66c46 (patch) | |
tree | 60b143e1cbd3915bc0c9cc382e58907ba84f128f /server | |
parent | 775276d4a987844fbbb88730f0eb11e285ae6e09 (diff) | |
download | vaadin-framework-64a029571955ee52b0c416b597fb718bc0a66c46.tar.gz vaadin-framework-64a029571955ee52b0c416b597fb718bc0a66c46.zip |
Declarative support for TextField, PasswordField and TextArea (#7749)
Change-Id: I41d04c55c65820f0270742468e94f47099783950
Diffstat (limited to 'server')
9 files changed, 355 insertions, 2 deletions
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 3728696233..fc3129d1ba 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -1790,6 +1790,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements Collection<String> attributes = super.getCustomAttributes(); attributes.add("readonly"); attributes.add("tabindex"); + // must be handled by subclasses + attributes.add("value"); return attributes; } diff --git a/server/src/com/vaadin/ui/PasswordField.java b/server/src/com/vaadin/ui/PasswordField.java index 107e40c149..b842fc5569 100644 --- a/server/src/com/vaadin/ui/PasswordField.java +++ b/server/src/com/vaadin/ui/PasswordField.java @@ -15,7 +15,12 @@ */ package com.vaadin.ui; +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; + import com.vaadin.data.Property; +import com.vaadin.ui.declarative.DesignAttributeHandler; +import com.vaadin.ui.declarative.DesignContext; /** * A field that is used to enter secret text information like passwords. The @@ -76,4 +81,40 @@ public class PasswordField extends AbstractTextField { this(); setCaption(caption); } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractField#synchronizeFromDesign(org.jsoup.nodes.Element + * , com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeFromDesign(Element design, + DesignContext designContext) { + super.synchronizeFromDesign(design, designContext); + AbstractTextField def = designContext.getDefaultInstance(this + .getClass()); + Attributes attr = design.attributes(); + String value = DesignAttributeHandler.readAttribute("value", attr, + def.getValue(), String.class); + setValue(value); + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractTextField#synchronizeToDesign(org.jsoup.nodes.Element + * , com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeToDesign(Element design, DesignContext designContext) { + super.synchronizeToDesign(design, designContext); + AbstractTextField def = designContext.getDefaultInstance(this + .getClass()); + Attributes attr = design.attributes(); + DesignAttributeHandler.writeAttribute("value", attr, getValue(), + def.getValue(), String.class); + } } diff --git a/server/src/com/vaadin/ui/TextArea.java b/server/src/com/vaadin/ui/TextArea.java index e38be8ad3c..70b9268228 100644 --- a/server/src/com/vaadin/ui/TextArea.java +++ b/server/src/com/vaadin/ui/TextArea.java @@ -16,8 +16,11 @@ package com.vaadin.ui; +import org.jsoup.nodes.Element; + import com.vaadin.data.Property; import com.vaadin.shared.ui.textarea.TextAreaState; +import com.vaadin.ui.declarative.DesignContext; /** * A text field that supports multi line editing. @@ -133,4 +136,30 @@ public class TextArea extends AbstractTextField { return getState(false).wordwrap; } + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractField#synchronizeFromDesign(org.jsoup.nodes.Element + * , com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeFromDesign(Element design, + DesignContext designContext) { + super.synchronizeFromDesign(design, designContext); + setValue(design.html()); + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractTextField#synchronizeToDesign(org.jsoup.nodes.Element + * , com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeToDesign(Element design, DesignContext designContext) { + super.synchronizeToDesign(design, designContext); + design.html(getValue()); + } } diff --git a/server/src/com/vaadin/ui/TextField.java b/server/src/com/vaadin/ui/TextField.java index fb1e4284a2..bb855c7b90 100644 --- a/server/src/com/vaadin/ui/TextField.java +++ b/server/src/com/vaadin/ui/TextField.java @@ -16,7 +16,12 @@ package com.vaadin.ui; +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; + import com.vaadin.data.Property; +import com.vaadin.ui.declarative.DesignAttributeHandler; +import com.vaadin.ui.declarative.DesignContext; /** * <p> @@ -99,4 +104,39 @@ public class TextField extends AbstractTextField { setCaption(caption); } + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractField#synchronizeFromDesign(org.jsoup.nodes.Element + * , com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeFromDesign(Element design, + DesignContext designContext) { + super.synchronizeFromDesign(design, designContext); + AbstractTextField def = designContext.getDefaultInstance(this + .getClass()); + Attributes attr = design.attributes(); + String value = DesignAttributeHandler.readAttribute("value", attr, + def.getValue(), String.class); + setValue(value); + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractTextField#synchronizeToDesign(org.jsoup.nodes.Element + * , com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeToDesign(Element design, DesignContext designContext) { + super.synchronizeToDesign(design, designContext); + AbstractTextField def = designContext.getDefaultInstance(this + .getClass()); + Attributes attr = design.attributes(); + DesignAttributeHandler.writeAttribute("value", attr, getValue(), + def.getValue(), String.class); + } } diff --git a/server/tests/src/com/vaadin/tests/layoutparser/all-components.html b/server/tests/src/com/vaadin/tests/layoutparser/all-components.html index 90d483ac8b..f633b06cb3 100644 --- a/server/tests/src/com/vaadin/tests/layoutparser/all-components.html +++ b/server/tests/src/com/vaadin/tests/layoutparser/all-components.html @@ -40,8 +40,12 @@ <!-- abstract field --> <v-text-field buffered validation-visible=false invalid-committed invalid-allowed=false required required-error="This is a required field" conversion-error="Input {0} cannot be parsed" tabindex=3 readonly /> - <!-- abstract text field --> - <v-text-field null-representation="" null-setting-allowed maxlength=10 columns=5 input-prompt="Please enter a value" text-change-event-mode="eager" text-change-timeout=2 /> + <!-- abstract text field, text field --> + <v-text-field null-representation="" null-setting-allowed maxlength=10 columns=5 input-prompt="Please enter a value" text-change-event-mode="eager" text-change-timeout=2 value="foo" /> + <!-- password field --> + <v-password-field null-representation="" null-setting-allowed maxlength=10 columns=5 input-prompt="Please enter a value" text-change-event-mode="eager" text-change-timeout=2 value="foo" /> + <!-- text area --> + <v-text-area rows=5 wordwrap=false >test value</v-text-area> </v-vertical-layout> </body> diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeFromDesign.java new file mode 100644 index 0000000000..787eac0a03 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeFromDesign.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.textarea; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.AbstractTextField; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for reading the value of the TextField from design + * + * @author Vaadin Ltd + */ +public class TestSynchronizeFromDesign extends TestCase { + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testValue() { + Element design = createDesign(); + AbstractTextField component = getComponent(); + component.synchronizeFromDesign(design, ctx); + assertEquals("test value", component.getValue()); + } + + private AbstractTextField getComponent() { + return new TextArea(); + } + + private Element createDesign() { + Attributes attributes = new Attributes(); + Element node = new Element(Tag.valueOf("v-text-area"), "", attributes); + node.html("test value"); + return node; + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeToDesign.java new file mode 100644 index 0000000000..a316b02ddc --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/textarea/TestSynchronizeToDesign.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.textarea; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.AbstractTextField; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing the value of the TextField to design + * + * @author Vaadin Ltd + */ +public class TestSynchronizeToDesign extends TestCase { + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testSynchronizeValue() { + Element design = createDesign(); + AbstractTextField component = getComponent(); + component.setValue("test value"); + component.synchronizeToDesign(design, ctx); + assertEquals("test value", design.html()); + assertFalse(design.hasAttr("value")); + } + + private AbstractTextField getComponent() { + return new TextArea(); + } + + private Element createDesign() { + Attributes attr = new Attributes(); + return new Element(Tag.valueOf("v-text-area"), "", attr); + } + +} diff --git a/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeFromDesign.java new file mode 100644 index 0000000000..2df0ab4855 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeFromDesign.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.textfield; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.AbstractTextField; +import com.vaadin.ui.TextField; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for reading the value of the TextField from design + * + * @author Vaadin Ltd + */ +public class TestSynchronizeFromDesign extends TestCase { + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testValue() { + Element design = createDesign(); + AbstractTextField component = getComponent(); + component.synchronizeFromDesign(design, ctx); + assertEquals("test value", component.getValue()); + } + + private AbstractTextField getComponent() { + return new TextField(); + } + + private Element createDesign() { + Attributes attributes = new Attributes(); + attributes.put("value", "test value"); + Element node = new Element(Tag.valueOf("v-text-field"), "", attributes); + return node; + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeToDesign.java new file mode 100644 index 0000000000..58d361e683 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/textfield/TestSynchronizeToDesign.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.textfield; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.ui.AbstractTextField; +import com.vaadin.ui.TextField; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Test case for writing the value of the TextField to design + * + * @author Vaadin Ltd + */ +public class TestSynchronizeToDesign extends TestCase { + private DesignContext ctx; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = new DesignContext(); + } + + public void testSynchronizeValue() { + Element design = createDesign(); + AbstractTextField component = getComponent(); + component.setValue("test value"); + component.synchronizeToDesign(design, ctx); + assertEquals("test value", design.attr("value")); + } + + private AbstractTextField getComponent() { + return new TextField(); + } + + private Element createDesign() { + Attributes attr = new Attributes(); + return new Element(Tag.valueOf("v-text-field"), "", attr); + } + +} |