Updated Branches:
  refs/heads/master 76982d56f -> 32e8e2f62

TAP5-2223 : New "secure" flag in Select component has a bug when using option 
groups


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/32e8e2f6
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/32e8e2f6
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/32e8e2f6

Branch: refs/heads/master
Commit: 32e8e2f626f9da1d64e13bbd7e572a33dd9cab22
Parents: 76982d5
Author: ffacon <ffa...@apache.org>
Authored: Fri Feb 14 15:32:48 2014 +0100
Committer: ffacon <ffa...@apache.org>
Committed: Fri Feb 14 15:32:48 2014 +0100

----------------------------------------------------------------------
 .../tapestry5/corelib/components/Select.java    |  2 +-
 tapestry-core/src/test/app1/OptionGroupForm.tml | 17 ++++
 .../tapestry5/integration/app1/data/Entity.java | 51 +++++++++++
 .../tapestry5/integration/app1/pages/Index.java |  2 +
 .../integration/app1/pages/OptionGroupForm.java | 92 ++++++++++++++++++++
 .../integration/app1/services/AppModule.java    | 23 +++++
 6 files changed, 186 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/32e8e2f6/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
 
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
index df55fcb..031d892 100644
--- 
a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
@@ -294,7 +294,7 @@ public class Select extends AbstractField
         {
             for (OptionGroupModel og : model.getOptionGroups())
             {
-                if (findInOptions(og.getOptions(), submittedValue))
+                if (findInOptions(og.getOptions(), asSubmitted))
                 {
                     return asSubmitted;
                 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/32e8e2f6/tapestry-core/src/test/app1/OptionGroupForm.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/OptionGroupForm.tml 
b/tapestry-core/src/test/app1/OptionGroupForm.tml
new file mode 100644
index 0000000..2722161
--- /dev/null
+++ b/tapestry-core/src/test/app1/OptionGroupForm.tml
@@ -0,0 +1,17 @@
+<html t:type="Border" 
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
+<h1>Simple Option Group </h1>
+
+    <t:form t:id="form">
+       <t:select t:id="select" t:value="entity" t:model="model"/>
+       <t:submit />
+    </t:form>
+
+<p>Entered data:</p>
+
+<ul>
+    <li>entity.id: [${entity.id}]</li>
+    <li>entity.label: [${entity.label}]</li>
+</ul>
+
+
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/32e8e2f6/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/Entity.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/Entity.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/Entity.java
new file mode 100644
index 0000000..40c2bdc
--- /dev/null
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/Entity.java
@@ -0,0 +1,51 @@
+// Copyright 2014 The Apache Software Foundation
+//
+// 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 org.apache.tapestry5.integration.app1.data;
+
+public class Entity {
+
+    private String id;
+    private String label;
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public Entity() {
+        super();
+    }
+
+    public Entity(String id, String label) {
+        super();
+        this.id = id;
+        this.label = label;
+    }
+
+    public boolean equals(Object obj) {
+        return (obj == this) || (obj instanceof Entity) && id != null && 
id.equals(((Entity) obj).getId());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/32e8e2f6/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
index 4df619a..0fa9207 100644
--- 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
@@ -291,6 +291,8 @@ public class Index
 
                     new Item("simpleform", "SimpleForm", "first pass at 
writing Form and TextField components"),
 
+                    new Item("OptionGroupForm", "OptionGroupForm", "Select 
with Option Group"),
+
                     new Item("validform", "ValidForm", "server-side input 
validation"),
 
                     new Item("ToDoListVolatile", "ToDo List (Volatile)", 
"Loops and Submit inside Form, volatile mode"),

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/32e8e2f6/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OptionGroupForm.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OptionGroupForm.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OptionGroupForm.java
new file mode 100644
index 0000000..d47aac3
--- /dev/null
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OptionGroupForm.java
@@ -0,0 +1,92 @@
+// Copyright 2014 The Apache Software Foundation
+//
+// 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 org.apache.tapestry5.integration.app1.pages;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.tapestry5.EventConstants;
+import org.apache.tapestry5.OptionGroupModel;
+import org.apache.tapestry5.OptionModel;
+import org.apache.tapestry5.SelectModel;
+import org.apache.tapestry5.annotations.OnEvent;
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.integration.app1.data.Entity;
+import org.apache.tapestry5.integration.app1.data.IncidentData;
+import org.apache.tapestry5.internal.OptionGroupModelImpl;
+import org.apache.tapestry5.internal.OptionModelImpl;
+import org.apache.tapestry5.util.AbstractSelectModel;
+
+
+
+public class OptionGroupForm {
+
+    @Property
+    @Persist
+    private Entity entity;
+
+    private static final List<Entity> entityList = Arrays.asList(new 
Entity("1", "label1"), new Entity("2", "label2"), new Entity("3", "label3"));
+
+    void onPrepare()
+    {
+        if (entity == null)
+        {
+            entity = new Entity();
+            entity.setId("1");
+            entity.setLabel("label1");
+        }
+    }
+
+    @OnEvent(value = EventConstants.SUCCESS, component = "form")
+    public void onFormSuccess() {
+        // It's OK we should come here on form submission
+    }
+
+    @OnEvent(value = EventConstants.FAILURE, component = "form")
+    public void onFormFailure() throws Exception {
+        throw new Exception("The form should have been successfully 
submitted");
+    }
+
+    public SelectModel getModel() {
+        return new AbstractSelectModel() {
+
+            private List<OptionGroupModel> groupModels = null;
+
+            public List<OptionModel> getOptions() {
+                return null;
+            }
+
+            public List<OptionGroupModel> getOptionGroups() {
+                if (groupModels == null) {
+                    computeModel();
+                }
+                return groupModels;
+            }
+
+            private void computeModel() {
+                groupModels = new ArrayList<OptionGroupModel>();
+                for (Entity entity : entityList) {
+                    List<OptionModel> options = new ArrayList<OptionModel>();
+                    options.add(new OptionModelImpl(entity.getLabel(), 
entity));
+
+                    OptionGroupModel groupModel = new 
OptionGroupModelImpl(entity.getLabel(), false, options);
+                    groupModels.add(groupModel);
+                }
+
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/32e8e2f6/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java
index d1849fe..a6cfe30 100644
--- 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java
@@ -16,6 +16,7 @@ package org.apache.tapestry5.integration.app1.services;
 
 import org.apache.tapestry5.SymbolConstants;
 import org.apache.tapestry5.ValueEncoder;
+import org.apache.tapestry5.integration.app1.data.Entity;
 import org.apache.tapestry5.integration.app1.data.ToDoItem;
 import org.apache.tapestry5.integration.app1.data.Track;
 import org.apache.tapestry5.internal.services.GenericValueEncoderFactory;
@@ -270,6 +271,28 @@ public class AppModule
         };
 
         configuration.add(ToDoItem.class, 
GenericValueEncoderFactory.create(todoEncoder));
+
+        final ValueEncoder<Entity> encoder = new ValueEncoder<Entity>() {
+            public String toClient(Entity value) {
+                return value.getId();
+            }
+
+            public Entity toValue(String clientValue) {
+                Entity entity = new Entity();
+                entity.setId(clientValue);
+                entity.setLabel("label" + clientValue);
+                return entity;
+            }
+        };
+
+        ValueEncoderFactory<Entity> valueEncoderFactory = new 
ValueEncoderFactory<Entity>() {
+
+            public ValueEncoder<Entity> create(Class<Entity> type) {
+                return encoder;
+            }
+        };
+
+        configuration.add(Entity.class, valueEncoderFactory);
     }
 
     public static void contributeComponentClassTransformWorker(

Reply via email to