You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/12/20 11:10:49 UTC

[2/4] git commit: WICKET-663 enhance ichoicerenderer with id->choice object lookup

WICKET-663 enhance ichoicerenderer with id->choice object lookup

expose #getChoicesModel() and use it in IChoiceRenderer#getObject(id, IModel)


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/dfd30907
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/dfd30907
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/dfd30907

Branch: refs/heads/master
Commit: dfd30907f9b008b8dfc1521c4c24d4022963dd34
Parents: 2c62645
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Dec 19 17:14:04 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Dec 19 17:14:04 2013 +0200

----------------------------------------------------------------------
 .../wicket/markup/html/form/AbstractChoice.java    | 17 +++++++++++------
 .../html/form/AbstractSingleSelectChoice.java      |  2 +-
 .../wicket/markup/html/form/ChoiceRenderer.java    |  8 +++++---
 .../wicket/markup/html/form/IChoiceRenderer.java   |  3 ++-
 4 files changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/dfd30907/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java
index e91ba36..7246e07 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java
@@ -64,7 +64,7 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
 	 */
 	public AbstractChoice(final String id)
 	{
-		this(id, new WildcardListModel<E>(new ArrayList<E>()), new ChoiceRenderer<E>());
+		this(id, new WildcardListModel<>(new ArrayList<E>()), new ChoiceRenderer<E>());
 	}
 
 	/**
@@ -77,7 +77,7 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
 	 */
 	public AbstractChoice(final String id, final List<? extends E> choices)
 	{
-		this(id, new WildcardListModel<E>(choices), new ChoiceRenderer<E>());
+		this(id, new WildcardListModel<>(choices), new ChoiceRenderer<E>());
 	}
 
 	/**
@@ -93,7 +93,7 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
 	public AbstractChoice(final String id, final List<? extends E> choices,
 		final IChoiceRenderer<? super E> renderer)
 	{
-		this(id, new WildcardListModel<E>(choices), renderer);
+		this(id, new WildcardListModel<>(choices), renderer);
 	}
 
 	/**
@@ -108,7 +108,7 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
 	 */
 	public AbstractChoice(final String id, IModel<T> model, final List<? extends E> choices)
 	{
-		this(id, model, new WildcardListModel<E>(choices), new ChoiceRenderer<E>());
+		this(id, model, new WildcardListModel<>(choices), new ChoiceRenderer<E>());
 	}
 
 	/**
@@ -126,7 +126,7 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
 	public AbstractChoice(final String id, IModel<T> model, final List<? extends E> choices,
 		final IChoiceRenderer<? super E> renderer)
 	{
-		this(id, model, new WildcardListModel<E>(choices), renderer);
+		this(id, model, new WildcardListModel<>(choices), renderer);
 	}
 
 	/**
@@ -210,6 +210,11 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
 		return choices;
 	}
 
+	public IModel<? extends List<? extends  E>> getChoicesModel()
+	{
+		return this.choices;
+	}
+
 	/**
 	 * Sets the list of choices
 	 * 
@@ -351,7 +356,7 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
 			appendOptionHtml(buffer, choice, index, selectedValue);
 		}
 
-		buffer.append("\n");
+		buffer.append('\n');
 		replaceComponentTagBody(markupStream, openTag, buffer);
 	}
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/dfd30907/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java
index b710980..51e21a7 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java
@@ -269,7 +269,7 @@ public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T, T>
 	 */
 	protected T convertChoiceIdToChoice(String id)
 	{
-		final List<? extends T> choices = getChoices();
+		final IModel<? extends List<? extends T>> choices = getChoicesModel();
 		final IChoiceRenderer<? super T> renderer = getChoiceRenderer();
 		T object = (T) renderer.getObject(id, choices);
 		return object;

http://git-wip-us.apache.org/repos/asf/wicket/blob/dfd30907/wicket-core/src/main/java/org/apache/wicket/markup/html/form/ChoiceRenderer.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/ChoiceRenderer.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/ChoiceRenderer.java
index 6cac9ec..75220ed 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/ChoiceRenderer.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/ChoiceRenderer.java
@@ -19,6 +19,7 @@ package org.apache.wicket.markup.html.form;
 import java.util.List;
 
 import org.apache.wicket.core.util.lang.PropertyResolver;
+import org.apache.wicket.model.IModel;
 
 /**
  * Default implementation of {@link org.apache.wicket.markup.html.form.IChoiceRenderer}. Usage:
@@ -156,12 +157,13 @@ public class ChoiceRenderer<T> implements IChoiceRenderer<T>
 	}
 
 	@Override
-	public T getObject(String id, List<? extends T> choices)
+	public T getObject(String id, IModel<? extends List<? extends T>> choices)
 	{
-		for (int index = 0; index < choices.size(); index++)
+		List<? extends T> _choices = choices.getObject();
+		for (int index = 0; index < _choices.size(); index++)
 		{
 			// Get next choice
-			final T choice = choices.get(index);
+			final T choice = _choices.get(index);
 			if (getIdValue(choice, index).equals(id))
 			{
 				return choice;

http://git-wip-us.apache.org/repos/asf/wicket/blob/dfd30907/wicket-core/src/main/java/org/apache/wicket/markup/html/form/IChoiceRenderer.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/IChoiceRenderer.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/IChoiceRenderer.java
index 9a8399e..1969982 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/IChoiceRenderer.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/IChoiceRenderer.java
@@ -18,6 +18,7 @@ package org.apache.wicket.markup.html.form;
 
 import java.util.List;
 
+import org.apache.wicket.model.IModel;
 import org.apache.wicket.util.io.IClusterable;
 
 /**
@@ -65,5 +66,5 @@ public interface IChoiceRenderer<T> extends IClusterable
 	 *          The list of all rendered choices
 	 * @return A choice from the list that has this {@code id}
 	 */
-	T getObject(String id, List<? extends T> choices);
+	T getObject(String id, IModel<? extends List<? extends T>> choices);
 }