Author: jdonnerstag
Date: Thu Jun 23 17:49:48 2011
New Revision: 1139016
URL: http://svn.apache.org/viewvc?rev=1139016&view=rev
Log:
fixed: CheckGroup's model update should be aligned with ListMultipleChoice
Issue: WICKET-3785
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.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=1139016&r1=1139015&r2=1139016&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
Thu Jun 23 17:49:48 2011
@@ -16,7 +16,6 @@
*/
package org.apache.wicket.markup.html.form;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -24,10 +23,14 @@ import org.apache.wicket.WicketRuntimeEx
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
import org.apache.wicket.model.util.CollectionModel;
import org.apache.wicket.util.convert.ConversionException;
+import org.apache.wicket.util.lang.Generics;
import org.apache.wicket.util.string.Strings;
import org.apache.wicket.util.visit.IVisit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -59,6 +62,8 @@ public class CheckGroup<T> extends FormC
{
private static final long serialVersionUID = 1L;
+ private static final Logger log =
LoggerFactory.getLogger(CheckGroup.class);
+
/**
* Constructor that will create a default model collection
*
@@ -97,13 +102,10 @@ public class CheckGroup<T> extends FormC
setRenderBodyOnly(true);
}
- /**
- * @see FormComponent#convertValue(String[])
- */
@Override
protected Collection<T> convertValue(String[] values) throws
ConversionException
{
- List<T> collection = new ArrayList<T>();
+ List<T> collection = Generics.newArrayList();
/*
* if the input is null we do not need to do anything since the
model collection has already
@@ -150,7 +152,14 @@ public class CheckGroup<T> extends FormC
}
/**
+ * If the model object exists, it is assumed to be a Collection, and it
is modified in-place.
+ * Then {@link Model#setObject(Object)} is called with the same
instance: it allows the Model to
+ * be notified of changes even when {@link Model#getObject()} returns a
different
+ * {@link Collection} at every invocation.
+ *
* @see FormComponent#updateModel()
+ * @throws UnsupportedOperationException
+ * if the model object Collection cannot be modified
*/
@Override
public void updateModel()
@@ -167,16 +176,26 @@ public class CheckGroup<T> extends FormC
collection.clear();
collection.addAll(getConvertedInput());
modelChanged();
+
+ // call model.setObject()
+ try
+ {
+ getModel().setObject(collection);
+ }
+ catch (Exception e)
+ {
+ // ignore this exception because it could be
that there
+ // is not setter for this collection.
+ log.info("no setter for the property attached
to " + this);
+ }
}
}
- /**
- * @see FormComponent#onComponentTag(ComponentTag)
- */
@Override
protected void onComponentTag(ComponentTag tag)
{
super.onComponentTag(tag);
+
// No longer applicable, breaks XHTML validation.
tag.remove("disabled");
tag.remove("name");
@@ -219,9 +238,6 @@ public class CheckGroup<T> extends FormC
return false;
}
- /**
- * @see org.apache.wicket.MarkupContainer#getStatelessHint()
- */
@Override
protected boolean getStatelessHint()
{
@@ -231,5 +247,4 @@ public class CheckGroup<T> extends FormC
}
return super.getStatelessHint();
}
-
}