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/02/06 09:52:00 UTC

[8/38] git commit: WICKET-5006 Improve null display value in AbstractSingleSelectChoice

WICKET-5006 Improve null display value in AbstractSingleSelectChoice


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

Branch: refs/heads/reference-guide
Commit: 74d22a507b61f075a6ff7a01850d3b37cb017e07
Parents: 9de6b6f
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Jan 28 11:33:11 2013 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Jan 28 11:33:11 2013 +0100

----------------------------------------------------------------------
 .../html/form/AbstractSingleSelectChoice.java      |   49 ++++++++++----
 1 files changed, 35 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/74d22a50/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 72a0e5b..8518ec5 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
@@ -311,12 +311,7 @@ public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T, T>
 		if (isNullValid())
 		{
 			// Null is valid, so look up the value for it
-			String option = getLocalizer().getStringIgnoreSettings(getNullValidKey(), this, null,
-				null);
-			if (Strings.isEmpty(option))
-			{
-				option = getLocalizer().getString("nullValid", this, "");
-			}
+			String option = getNullValidDisplayValue();
 
 			// The <option> tag buffer
 			final AppendingStringBuffer buffer = new AppendingStringBuffer(64 + option.length());
@@ -340,14 +335,7 @@ public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T, T>
 			if ("".equals(selectedValue))
 			{
 				// Force the user to pick a non-null value
-				String option = getLocalizer().getStringIgnoreSettings(getNullKey(), this, null,
-					null);
-
-				if (Strings.isEmpty(option))
-				{
-					option = getLocalizer().getString("null", this, CHOOSE_ONE);
-				}
-
+				String option = getNullKeyDisplayValue();
 				return "\n<option selected=\"selected\" value=\"\">" + option + "</option>";
 			}
 		}
@@ -355,6 +343,22 @@ public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T, T>
 	}
 
 	/**
+	 * Returns the display value for the null value. The default behavior is to look the value up by
+	 * using the key from <code>getNullValidKey()</code>.
+	 *
+	 * @return The value to display for null
+	 */
+	protected String getNullValidDisplayValue()
+	{
+		String option = getLocalizer().getStringIgnoreSettings(getNullValidKey(), this, null, null);
+		if (Strings.isEmpty(option))
+		{
+			option = getLocalizer().getString("nullValid", this, "");
+		}
+		return option;
+	}
+
+	/**
 	 * Return the localization key for nullValid value
 	 * 
 	 * @return getId() + ".nullValid"
@@ -365,6 +369,23 @@ public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T, T>
 	}
 
 	/**
+	 * Returns the display value if null is not valid but is selected. The default behavior is to
+	 * look the value up by using the key from <code>getNullKey()</code>.
+	 *
+	 * @return The value to display if null is not value but selected, e.g. "Choose One"
+	 */
+	protected String getNullKeyDisplayValue()
+	{
+		String option = getLocalizer().getStringIgnoreSettings(getNullKey(), this, null, null);
+
+		if (Strings.isEmpty(option))
+		{
+			option = getLocalizer().getString("null", this, CHOOSE_ONE);
+		}
+		return option;
+	}
+
+	/**
 	 * Return the localization key for null value
 	 * 
 	 * @return getId() + ".null"