Author: svenmeier Date: Fri Sep 16 09:27:15 2011 New Revision: 1171470 URL: http://svn.apache.org/viewvc?rev=1171470&view=rev Log: WICKET-3962 align Select with CheckGroup and RadioGroup, i.e. use uuid for values
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java?rev=1171470&r1=1171469&r2=1171470&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java (original) +++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java Fri Sep 16 09:27:15 2011 @@ -136,8 +136,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/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java?rev=1171470&r1=1171469&r2=1171470&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java (original) +++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java Fri Sep 16 09:27:15 2011 @@ -121,7 +121,7 @@ public class RadioGroup<T> extends FormC value + "] for RadioGroup component [" + getPath() + - "] is illegal because it does not contain relative path to a Radio component. " + + "] is illegal because it 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."); } Modified: wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java?rev=1171470&r1=1171469&r2=1171470&view=diff ============================================================================== --- wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java (original) +++ wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java Fri Sep 16 09:27:15 2011 @@ -27,6 +27,8 @@ import org.apache.wicket.markup.html.for import org.apache.wicket.model.IModel; import org.apache.wicket.util.lang.Objects; import org.apache.wicket.util.string.Strings; +import org.apache.wicket.util.visit.IVisit; +import org.apache.wicket.util.visit.IVisitor; /** @@ -99,18 +101,18 @@ public class Select<T> extends FormCompo boolean supportsMultiple = getModelObject() instanceof Collection; /* - * the input contains an array of full path of the selected option components unless nothing - * was selected in which case the input contains null + * + * 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 [" + @@ -118,35 +120,39 @@ 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 (String path : paths) + for (int i = 0; i < values.length; 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 = visitChildren(SelectOption.class, + new IVisitor<SelectOption<T>, SelectOption<T>>() + { + public void component(SelectOption<T> option, IVisit<SelectOption<T>> visit) + { + if (String.valueOf(option.getValue()).equals(value)) + { + visit.stop(option); + } + } + }); if (option == null) { throw new WicketRuntimeException( "submitted http post value [" + - Arrays.toString(paths) + + Arrays.toString(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()); } @@ -173,7 +179,7 @@ public class Select<T> extends FormCompo /** * @see FormComponent#updateModel() */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings( { "unchecked", "rawtypes" }) @Override public void updateModel() { Modified: wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java?rev=1171470&r1=1171469&r2=1171470&view=diff ============================================================================== --- wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java (original) +++ wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java Fri Sep 16 09:27:15 2011 @@ -37,6 +37,12 @@ public class SelectOption<T> extends Web private static final long serialVersionUID = 1L; /** + * page-scoped uuid of this option. this property must not be accessed directly, instead + * {@link #getValue()} must be used + */ + private int uuid = -1; + + /** * @see WebMarkupContainer#WebMarkupContainer(String) */ public SelectOption(final 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().getAutoIndex(); + } + 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); if (select.isSelected(this)) {