summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2015-07-07 21:49:45 +0300
committerMika Murtojarvi <mika@vaadin.com>2015-09-11 17:01:37 +0300
commit6dd7022bca8fe8acfb74a5d34d4ff9cef7c7e43b (patch)
tree03db969ab0b7b0588a77279607b17b44de3e8bf6
parented592a47f852634b74a272b7e777379ba13401aa (diff)
downloadvaadin-framework-6dd7022bca8fe8acfb74a5d34d4ff9cef7c7e43b.tar.gz
vaadin-framework-6dd7022bca8fe8acfb74a5d34d4ff9cef7c7e43b.zip
Make it possible to avoid select caption conversion (#16845)
Change-Id: If88b7cf6298a24cfad3c936a1af566ed919ec0e7
-rw-r--r--server/src/com/vaadin/ui/AbstractSelect.java41
-rw-r--r--uitest/src/com/vaadin/tests/components/select/SelectWithIntegers.java46
-rw-r--r--uitest/src/com/vaadin/tests/components/select/SelectWithIntegersTest.java37
3 files changed, 100 insertions, 24 deletions
diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java
index 498ae2de0a..5152a38a85 100644
--- a/server/src/com/vaadin/ui/AbstractSelect.java
+++ b/server/src/com/vaadin/ui/AbstractSelect.java
@@ -49,6 +49,7 @@ import com.vaadin.server.KeyMapper;
import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
import com.vaadin.server.Resource;
+import com.vaadin.server.VaadinSession;
import com.vaadin.shared.ui.combobox.FilteringMode;
import com.vaadin.shared.ui.dd.VerticalDropLocation;
import com.vaadin.ui.declarative.DesignAttributeHandler;
@@ -80,10 +81,17 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
public enum ItemCaptionMode {
/**
+ * Item caption mode: Item's ID converted to a String using
+ * {@link VaadinSession#getConverterFactory()} is used as caption.
+ */
+ ID,
+ /**
* Item caption mode: Item's ID's <code>String</code> representation is
* used as caption.
+ *
+ * @since
*/
- ID,
+ ID_TOSTRING,
/**
* Item caption mode: Item's <code>String</code> representation is used
* as caption.
@@ -97,8 +105,9 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
INDEX,
/**
* Item caption mode: If an Item has a caption it's used, if not, Item's
- * ID's <code>String</code> representation is used as caption. <b>This
- * is the default</b>.
+ * ID converted to a String using
+ * {@link VaadinSession#getConverterFactory()} is used as caption.
+ * <b>This is the default</b>.
*/
EXPLICIT_DEFAULTS_ID,
/**
@@ -1190,7 +1199,9 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
case ID:
caption = idToCaption(itemId);
break;
-
+ case ID_TOSTRING:
+ caption = itemId.toString();
+ break;
case INDEX:
if (items instanceof Container.Indexed) {
caption = String.valueOf(((Container.Indexed) items)
@@ -1297,27 +1308,9 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
/**
* Sets the item caption mode.
*
+ * See {@link ItemCaptionMode} for a description of the modes.
* <p>
- * The mode can be one of the following ones:
- * <ul>
- * <li><code>ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID</code> : Items
- * Id-objects <code>toString</code> is used as item caption. If caption is
- * explicitly specified, it overrides the id-caption.
- * <li><code>ITEM_CAPTION_MODE_ID</code> : Items Id-objects
- * <code>toString</code> is used as item caption.</li>
- * <li><code>ITEM_CAPTION_MODE_ITEM</code> : Item-objects
- * <code>toString</code> is used as item caption.</li>
- * <li><code>ITEM_CAPTION_MODE_INDEX</code> : The index of the item is used
- * as item caption. The index mode can only be used with the containers
- * implementing <code>Container.Indexed</code> interface.</li>
- * <li><code>ITEM_CAPTION_MODE_EXPLICIT</code> : The item captions must be
- * explicitly specified.</li>
- * <li><code>ITEM_CAPTION_MODE_PROPERTY</code> : The item captions are read
- * from property, that must be specified with
- * <code>setItemCaptionPropertyId</code>.</li>
- * </ul>
- * The <code>ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID</code> is the default
- * mode.
+ * {@link ItemCaptionMode#EXPLICIT_DEFAULTS_ID} is the default mode.
* </p>
*
* @param mode
diff --git a/uitest/src/com/vaadin/tests/components/select/SelectWithIntegers.java b/uitest/src/com/vaadin/tests/components/select/SelectWithIntegers.java
new file mode 100644
index 0000000000..3012105ae9
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/select/SelectWithIntegers.java
@@ -0,0 +1,46 @@
+/*
+ * 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.components.select;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.AbstractSelect;
+import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
+import com.vaadin.ui.ListSelect;
+
+public class SelectWithIntegers extends AbstractTestUI {
+ private final List<Integer> years = Arrays.asList(2014, 2015, 2016);
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(createSelect("Default", null));
+ addComponent(createSelect("ID_TOSTRING", ItemCaptionMode.ID_TOSTRING));
+ }
+
+ private AbstractSelect createSelect(String caption, ItemCaptionMode mode) {
+ ListSelect listSelect = new ListSelect(caption, years);
+ listSelect.setRows(years.size());
+ listSelect.setNullSelectionAllowed(false);
+ if (mode != null) {
+ listSelect.setItemCaptionMode(mode);
+ }
+ return listSelect;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/select/SelectWithIntegersTest.java b/uitest/src/com/vaadin/tests/components/select/SelectWithIntegersTest.java
new file mode 100644
index 0000000000..bbef30bf1d
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/select/SelectWithIntegersTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.components.select;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ListSelectElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class SelectWithIntegersTest extends SingleBrowserTest {
+ @Test
+ public void testSelectWithIntegers() {
+ openTestURL();
+
+ ListSelectElement defaultSelect = $(ListSelectElement.class).caption(
+ "Default").first();
+ ListSelectElement toStringSelect = $(ListSelectElement.class).caption(
+ "ID_TOSTRING").first();
+
+ Assert.assertEquals("2,014", defaultSelect.getOptions().get(0));
+ Assert.assertEquals("2014", toStringSelect.getOptions().get(0));
+ }
+}