Author: svenmeier
Date: Tue Dec 6 13:17:43 2011
New Revision: 1210896
URL: http://svn.apache.org/viewvc?rev=1210896&view=rev
Log:
WICKET-4276 Select keep selection on form error
Added:
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTest.java
(with props)
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.html
(with props)
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.java
(with props)
Modified:
wicket/branches/wicket-1.5.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java
Modified:
wicket/branches/wicket-1.5.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.5.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java?rev=1210896&r1=1210895&r2=1210896&view=diff
==============================================================================
---
wicket/branches/wicket-1.5.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java
(original)
+++
wicket/branches/wicket-1.5.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java
Tue Dec 6 13:17:43 2011
@@ -214,7 +214,7 @@ public class Select<T> extends FormCompo
* Checks if the specified option is selected based on raw input
*
* @param option
- * @return true} iff the option is selected
+ * @return {@code true} if the option is selected, {@code false}
otherwise
*/
boolean isSelected(final SelectOption<?> option)
{
@@ -223,12 +223,13 @@ public class Select<T> extends FormCompo
// if the raw input is specified use that, otherwise use model
if (hasRawInput())
{
- String[] paths = getInputAsArray();
- if ((paths != null) && (paths.length > 0))
+ String[] values = getInputAsArray();
+ if (values != null && values.length > 0)
{
- for (String path : paths)
+ for (int i = 0; i < values.length; i++)
{
- if (path.equals(option.getPath()))
+ String value = values[i];
+ if (value.equals(option.getValue()))
{
return true;
}
Added:
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTest.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTest.java?rev=1210896&view=auto
==============================================================================
---
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTest.java
(added)
+++
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTest.java
Tue Dec 6 13:17:43 2011
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.wicket.extensions.markup.html.form.select;
+
+import org.apache.wicket.WicketTestCase;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test for {@link Select}.
+ */
+public class SelectTest extends WicketTestCase
+{
+
+ private SelectTestPage page;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ page = new SelectTestPage();
+ tester.startPage(page);
+ }
+
+ /**
+ * WICKET-4276
+ *
+ * @throws Exception
+ */
+ @Test
+ public void rawInputKeepsSelectionOnError() throws Exception
+ {
+ tester.getRequest().setParameter("select",
page.option1.getValue());
+
+ page.form.onFormSubmitted();
+
+ // form has error ...
+ boolean hasError = page.form.hasError();
+ assertTrue(hasError);
+
+ // ... but option1 is selected anyway through rawInput
+ assertTrue(page.select.isSelected(page.option1));
+ }
+}
Propchange:
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.html
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.html?rev=1210896&view=auto
==============================================================================
---
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.html
(added)
+++
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.html
Tue Dec 6 13:17:43 2011
@@ -0,0 +1,14 @@
+<html>
+<head><title>SelectTestPage</title></head>
+<body>
+ <form wicket:id="form">
+ <select wicket:id="select">
+ <option wicket:id="option0"></option>
+ <option wicket:id="option1"></option>
+ <option wicket:id="option2"></option>
+ </select>
+
+ <input type="text" wicket:id="text"/>
+ </form>
+</body>
+</html>
Propchange:
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.java?rev=1210896&view=auto
==============================================================================
---
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.java
(added)
+++
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.java
Tue Dec 6 13:17:43 2011
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.wicket.extensions.markup.html.form.select;
+
+import org.apache.wicket.extensions.markup.html.form.select.SelectOption;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.Model;
+
+/**
+ */
+public class SelectTestPage extends WebPage
+{
+
+ public Form<Void> form;
+ public Select<String> select;
+ public SelectOption<String> option1;
+
+ public SelectTestPage()
+ {
+ form = new Form<Void>("form");
+ add(form);
+
+ select = new Select<String>("select", new Model<String>(null));
+ form.add(select);
+
+ select.add(new SelectOption<String>("option0", new
Model<String>("OPTION_0")));
+ select.add(option1 = new SelectOption<String>("option1", new
Model<String>("OPTION_1")));
+ select.add(new SelectOption<String>("option2", new
Model<String>("OPTION_2")));
+
+ form.add(new TextField<String>("text", new
Model<String>(null)).setRequired(true));
+ }
+}
\ No newline at end of file
Propchange:
wicket/branches/wicket-1.5.x/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/form/select/SelectTestPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain