You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2011/09/16 09:10:18 UTC
svn commit: r1171403 - in /wicket/branches/wicket-1.4.x:
wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/
wicket/src/main/java/org/apache/wicket/markup/html/form/
Author: svenmeier
Date: Fri Sep 16 07:10:18 2011
New Revision: 1171403
URL: http://svn.apache.org/viewvc?rev=1171403&view=rev
Log:
WICKET-3962 align Select with CheckGroup and RadioGroup, i.e. use uuid for values
Modified:
wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java
wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java
Modified: wicket/branches/wicket-1.4.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.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java?rev=1171403&r1=1171402&r2=1171403&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java (original)
+++ wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java Fri Sep 16 07:10:18 2011
@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.apache.wicket.Component;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.FormComponent;
@@ -89,24 +90,25 @@ public class Select<T> extends FormCompo
super(id, model);
}
+ @SuppressWarnings("unchecked")
@Override
protected void convertInput()
{
boolean supportsMultiple = getDefaultModelObject() instanceof Collection;
/*
- * the input contains an array of full path of the selected option components unless nothing
+ * the input contains an array of values of the selected option components unless nothing
* was selected in which case the input contains null
*/
- String[] paths = getInputAsArray();
+ String[] values = getInputAsArray();
- if (paths == null || paths.length == 0)
+ if (values == null || values.length == 0)
{
setConvertedInput(null);
return;
}
- if (!supportsMultiple && paths.length > 1)
+ if (!supportsMultiple && values.length > 1)
{
throw new WicketRuntimeException(
"The model of Select component [" +
@@ -114,40 +116,43 @@ public class Select<T> extends FormCompo
"] is not of type java.util.Collection, but more then one SelectOption component has been selected. Either remove the multiple attribute from the select tag or make the model of the Select component a collection");
}
- List<Object> converted = new ArrayList<Object>(paths.length);
+ List<Object> converted = new ArrayList<Object>(values.length);
/*
* if the input is null we do not need to do anything since the model collection has already
* been cleared
*/
- for (int i = 0; i < paths.length; i++)
+ for (int i = 0; i < values.length; i++)
{
- String path = paths[i];
- if (!Strings.isEmpty(path))
+ final String value = values[i];
+ if (!Strings.isEmpty(value))
{
- /*
- * option component path sans select component path = relative path from group to
- * option since we know the option is child of select
- */
- path = path.substring(getPath().length() + 1);
-
- // retrieve the selected option component
- SelectOption<?> option = (SelectOption<?>)get(path);
+ SelectOption<T> option = (SelectOption<T>)visitChildren(SelectOption.class,
+ new Component.IVisitor<SelectOption<T>>()
+ {
+ public Object component(SelectOption<T> option)
+ {
+ if (String.valueOf(option.getValue()).equals(value))
+ {
+ return option;
+ }
+ return CONTINUE_TRAVERSAL;
+ }
+ });
if (option == null)
{
throw new WicketRuntimeException(
"submitted http post value [" +
- paths.toString() +
+ Strings.join(",", values) +
"] for SelectOption component [" +
getPath() +
- "] contains an illegal relative path element [" +
- path +
- "] which does not point to an SelectOption component. Due to this the Select component cannot resolve the selected SelectOption component pointed to by the illegal value. A possible reason is that component hierarchy changed between rendering and form submission.");
+ "] contains an illegal value [" +
+ value +
+ "] which does not point to a SelectOption component. Due to this the Select component cannot resolve the selected SelectOption component pointed to by the illegal value. A possible reason is that component hierarchy changed between rendering and form submission.");
}
converted.add(option.getDefaultModelObject());
}
-
}
if (converted.isEmpty())
Modified: wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java?rev=1171403&r1=1171402&r2=1171403&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java (original)
+++ wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java Fri Sep 16 07:10:18 2011
@@ -37,6 +37,12 @@ public class SelectOption<T> extends Web
private static final long serialVersionUID = 1L;
/**
+ * page-scoped uuid of this check. this property must not be accessed directly, instead
+ * {@link #getValue()} must be used
+ */
+ private int uuid = -1;
+
+ /**
* @see WebMarkupContainer#WebMarkupContainer(String)
*/
public SelectOption(String id)
@@ -54,6 +60,20 @@ public class SelectOption<T> extends Web
super(id, model);
}
+ /**
+ * Form submission value used for this select option. This string will appear as the value of
+ * the <code>value</code> html attribute for the <code>option</code> tag.
+ *
+ * @return form submission value
+ */
+ public String getValue()
+ {
+ if (uuid < 0)
+ {
+ uuid = getPage().getAutoIndex2();
+ }
+ return "option" + uuid;
+ }
/**
* @see Component#onComponentTag(ComponentTag)
@@ -75,8 +95,10 @@ public class SelectOption<T> extends Web
"] cannot find its parent Select. All SelectOption components must be a child of or below in the hierarchy of a Select component.");
}
- // assign name and value
- tag.put("value", getPath());
+ final String uuid = getValue();
+
+ // assign value
+ tag.put("value", uuid);
boolean isSelected = false;
Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java?rev=1171403&r1=1171402&r2=1171403&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java Fri Sep 16 07:10:18 2011
@@ -139,8 +139,7 @@ public class CheckGroup<T> extends FormC
Strings.join(",", values) +
"] for CheckGroup component [" +
getPath() +
- "] contains an illegal relative path " +
- "element [" +
+ "] contains an illegal value [" +
value +
"] which does not point to a Check component. Due to this the CheckGroup component cannot resolve the selected Check component pointed to by the illegal value. A possible reason is that component hierarchy changed between rendering and form submission.");
}
Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java?rev=1171403&r1=1171402&r2=1171403&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java Fri Sep 16 07:10:18 2011
@@ -123,11 +123,11 @@ public class RadioGroup<T> extends FormC
value +
"] for RadioGroup component [" +
getPath() +
- "] is illegal because it does not contain relative path to a Radio component. " +
- "Due to this the RadioGroup component cannot resolve the selected Radio component pointed to by the illegal value. A possible reason is that component hierarchy changed between rendering and form submission.");
+ "] is an illegal value [" +
+ value +
+ "] which does not point to a Radio component. Due to this the RadioGroup component cannot resolve the selected Radio component pointed to by the illegal value. A possible reason is that component hierarchy changed between rendering and form submission.");
}
-
// assign the value of the group's model
return choice.getModelObject();
}