You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2012/04/04 11:09:23 UTC
[7/7] git commit: WICKET-2674 AbstractChoice Option Style Hook
WICKET-2674 AbstractChoice Option Style Hook
Move the code that sets AbstractChoice's attributes in a separate overrideable method.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f4f68ef3
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f4f68ef3
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f4f68ef3
Branch: refs/heads/sandbox/atmosphere
Commit: f4f68ef3bbbb3e3ec3270b778f5dc8236dc77011
Parents: 34b0215
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue Apr 3 10:24:22 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Tue Apr 3 10:24:22 2012 +0200
----------------------------------------------------------------------
.../wicket/markup/html/form/AbstractChoice.java | 49 +++++++++++----
.../extensions/markup/html/form/select/Select.java | 9 +++-
.../markup/html/form/select/SelectOption.java | 4 +-
.../markup/html/form/select/SelectOptions.java | 6 +-
4 files changed, 48 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/f4f68ef3/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 45b3b92..b094a54 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
@@ -30,6 +30,11 @@ import org.apache.wicket.util.string.Strings;
/**
* Abstract base class for all choice (html select) options.
+ * <p>
+ * This component uses String concatenation to keep its memory footprint light.
+ * Use Select, SelectOptions and SelectOption from wicket-extensions for more
+ * sophisticated needs.
+ * </p>
*
* @author Jonathan Locke
* @author Eelco Hillenius
@@ -382,19 +387,8 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
}
buffer.append("\n<option ");
- if (isSelected(choice, index, selected))
- {
- buffer.append("selected=\"selected\" ");
- }
-
- if (isDisabled(choice, index, selected))
- {
- buffer.append("disabled=\"disabled\" ");
- }
-
- buffer.append("value=\"");
- buffer.append(Strings.escapeMarkup(renderer.getIdValue(choice, index)));
- buffer.append("\">");
+ setOptionAttributes(buffer, choice, index, selected);
+ buffer.append(">");
String display = displayValue;
if (localizeDisplayValues())
@@ -413,6 +407,35 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
}
/**
+ * Sets the attributes of a single choice into the provided buffer.
+ *
+ * @param buffer
+ * Appending string buffer that will have the generated html appended
+ * @param choice
+ * Choice object
+ * @param index
+ * The index of this option
+ * @param selected
+ * The currently selected string value
+ */
+ protected void setOptionAttributes(AppendingStringBuffer buffer, E choice, int index, String selected)
+ {
+ if (isSelected(choice, index, selected))
+ {
+ buffer.append("selected=\"selected\" ");
+ }
+
+ if (isDisabled(choice, index, selected))
+ {
+ buffer.append("disabled=\"disabled\" ");
+ }
+
+ buffer.append("value=\"");
+ buffer.append(Strings.escapeMarkup(renderer.getIdValue(choice, index)));
+ buffer.append("\"");
+ }
+
+ /**
* Method to override if you want special escaping of the options html.
*
* @param displayValue
http://git-wip-us.apache.org/repos/asf/wicket/blob/f4f68ef3/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java
index 083ccc3..7969fe3 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/Select.java
@@ -34,7 +34,7 @@ import org.apache.wicket.util.visit.IVisitor;
/**
* Component that represents a <code><select></code> box. Elements are provided by one or more
- * <code>SelectChoice</code> or <code>SelectOptions</code> components in the hierarchy below the
+ * <code>SelectOptions</code> components in the hierarchy below the
* <code>Select</code> component.
*
* Advantages to the standard choice components is that the user has a lot more control over the
@@ -63,10 +63,17 @@ import org.apache.wicket.util.visit.IVisitor;
*
* Note that you don't need to add component(s) for the <option> tag - they are created by
* SelectOptions
+ * </p>
* <p>
+ * <strong>Note</strong>: due to the usage of a SelectOption for each <option> the memory footprint
+ * of the page will grow with the number of <option>s you need. Consider using
+ * {@link org.apache.wicket.markup.html.form.DropDownChoice} component if it is able to fulfill your
+ * requirements.
+ * </p>
*
* @see SelectOption
* @see SelectOptions
+ * @see org.apache.wicket.markup.html.form.DropDownChoice
*
* @author Igor Vaynberg
* @param <T>
http://git-wip-us.apache.org/repos/asf/wicket/blob/f4f68ef3/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java
index 0aa32de..564eead 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOption.java
@@ -24,9 +24,7 @@ import org.apache.wicket.model.IModel;
/**
* Component representing a single <code><option></code> html element
- *
- * TODO Post 1.2: General: Example
- *
+ *
* @see Select
* @param <T>
*
http://git-wip-us.apache.org/repos/asf/wicket/blob/f4f68ef3/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOptions.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOptions.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOptions.java
index a0d1f3e..88a96f6 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOptions.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/select/SelectOptions.java
@@ -32,9 +32,9 @@ import org.apache.wicket.model.util.WildcardCollectionModel;
* Example markup:
*
* <pre>
- * <code>
- * <wicket:container wicket:id="selectOptions"><option wicket:id="option"></option></wicket:contaner>
- * </code>
+ * <code>
+ * <wicket:container wicket:id="selectOptions"><option wicket:id="option"></option></wicket:container>
+ * </code>
* </pre>
*
* @param <T>