You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2018/05/28 16:35:51 UTC
wicket git commit: WICKET-6555 reuse code
Repository: wicket
Updated Branches:
refs/heads/WICKET-6555-choices [created] 263fcdc65
WICKET-6555 reuse code
override getDefaultChoice() return empty string
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/263fcdc6
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/263fcdc6
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/263fcdc6
Branch: refs/heads/WICKET-6555-choices
Commit: 263fcdc65967330310df95896ca9e935bdd837f9
Parents: 4d4a690
Author: Sven Meier <sv...@apache.org>
Authored: Mon May 28 18:34:26 2018 +0200
Committer: Sven Meier <sv...@apache.org>
Committed: Mon May 28 18:34:26 2018 +0200
----------------------------------------------------------------------
.../wicket/markup/html/form/AbstractChoice.java | 109 +++++++--
.../html/form/CheckBoxMultipleChoice.java | 228 ++++++-------------
.../wicket/markup/html/form/RadioChoice.java | 226 +++++-------------
.../html/form/CheckBoxMultipleChoiceTest.java | 12 +-
.../markup/html/form/RadioChoiceTest.java | 8 +-
5 files changed, 228 insertions(+), 355 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/263fcdc6/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 fd1cacf..c5d44c4 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
@@ -58,22 +58,84 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
/**
* will render the label before the choice
*/
- BEFORE,
+ BEFORE {
+ @Override
+ void before(AppendingStringBuffer buffer, String idAttr, StringBuilder extraLabelAttributes, CharSequence renderValue)
+ {
+ buffer.append("<label for=\"")
+ .append(Strings.escapeMarkup(idAttr))
+ .append('"')
+ .append(extraLabelAttributes)
+ .append('>')
+ .append(renderValue)
+ .append("</label>");
+ }
+ },
/**
* will render the label after the choice
*/
- AFTER,
+ AFTER {
+ @Override
+ void after(AppendingStringBuffer buffer, String idAttr, StringBuilder extraLabelAttributes, CharSequence renderValue)
+ {
+ buffer.append("<label for=\"")
+ .append(Strings.escapeMarkup(idAttr))
+ .append('"')
+ .append(extraLabelAttributes)
+ .append('>')
+ .append(renderValue)
+ .append("</label>");
+ }
+ },
/**
* render the label around and the text will be before the the choice
*/
- WRAP_BEFORE,
+ WRAP_BEFORE {
+ @Override
+ void before(AppendingStringBuffer buffer, String idAttr, StringBuilder extraLabelAttributes, CharSequence renderValue)
+ {
+ buffer.append("<label")
+ .append(extraLabelAttributes)
+ .append('>')
+ .append(renderValue)
+ .append(' ');
+ }
+
+ @Override
+ void after(AppendingStringBuffer buffer, String idAttr, StringBuilder extraLabelAttributes, CharSequence renderValue)
+ {
+ buffer.append("</label>");
+ }
+ },
/**
* render the label around and the text will be after the the choice
*/
- WRAP_AFTER
+ WRAP_AFTER {
+ @Override
+ void before(AppendingStringBuffer buffer, String idAttr, StringBuilder extraLabelAttributes, CharSequence renderValue)
+ {
+ buffer.append("<label")
+ .append(extraLabelAttributes)
+ .append('>');
+ }
+
+ @Override
+ void after(AppendingStringBuffer buffer, String idAttr, StringBuilder extraLabelAttributes, CharSequence renderValue)
+ {
+ buffer.append(' ')
+ .append(renderValue)
+ .append("</label>");
+ }
+ };
+
+ void before(AppendingStringBuffer buffer, String idAttr, StringBuilder extraLabelAttributes, CharSequence renderValue) {
+ }
+
+ void after(AppendingStringBuffer buffer, String idAttr, StringBuilder extraLabelAttributes, CharSequence renderValue) {
+ }
}
/** The list of objects. */
@@ -403,9 +465,19 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
* @param selected
* The currently selected string value
*/
- @SuppressWarnings("unchecked")
- protected void appendOptionHtml(AppendingStringBuffer buffer, E choice, int index,
- String selected)
+ protected void appendOptionHtml(AppendingStringBuffer buffer, E choice, int index, String selected)
+ {
+ CharSequence renderValue = renderValue(choice);
+
+ buffer.append("\n<option ");
+ setOptionAttributes(buffer, choice, index, selected);
+ buffer.append('>');
+ buffer.append(renderValue);
+ buffer.append("</option>");
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ CharSequence renderValue(E choice)
{
Object objectValue = renderer.getDisplayValue(choice);
Class<?> objectClass = (objectValue == null ? null : objectValue.getClass());
@@ -413,7 +485,6 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
String displayValue = "";
if (objectClass != null && objectClass != String.class)
{
- @SuppressWarnings("rawtypes")
IConverter converter = getConverter(objectClass);
displayValue = converter.convertToString(objectValue, getLocale());
}
@@ -421,25 +492,21 @@ public abstract class AbstractChoice<T, E> extends FormComponent<T>
{
displayValue = objectValue.toString();
}
-
- buffer.append("\n<option ");
- setOptionAttributes(buffer, choice, index, selected);
- buffer.append('>');
-
- String display = displayValue;
+
if (localizeDisplayValues())
{
- display = getLocalizer().getString(displayValue, this, displayValue);
+ displayValue = getLocalizer().getString(getId() + "." + displayValue, this, "");
+ if (Strings.isEmpty(displayValue)) {
+ displayValue = getLocalizer().getString(displayValue, this, displayValue);
+ }
}
-
- CharSequence escaped = display;
+
if (getEscapeModelStrings())
{
- escaped = escapeOptionHtml(display);
+ return escapeOptionHtml(displayValue);
}
-
- buffer.append(escaped);
- buffer.append("</option>");
+
+ return displayValue;
}
/**
http://git-wip-us.apache.org/repos/asf/wicket/blob/263fcdc6/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
index f1c3520..8fab392 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
@@ -22,10 +22,8 @@ import java.util.Map;
import org.apache.wicket.Page;
import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.model.IModel;
import org.apache.wicket.settings.DebugSettings;
-import org.apache.wicket.util.convert.IConverter;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.AppendingStringBuffer;
import org.apache.wicket.util.string.Strings;
@@ -340,31 +338,12 @@ public class CheckBoxMultipleChoice<T> extends ListMultipleChoice<T>
}
/**
- * @see org.apache.wicket.Component#onComponentTagBody(org.apache.wicket.markup.MarkupStream,
- * org.apache.wicket.markup.ComponentTag)
+ * Not supported - does nothing.
*/
@Override
- public final void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
+ protected CharSequence getDefaultChoice(String selectedValue)
{
- // Iterate through choices
- final List<? extends T> choices = getChoices();
-
- // Buffer to hold generated body
- final AppendingStringBuffer buffer = new AppendingStringBuffer(70 * (choices.size() + 1));
-
- // Value of this choice
- final String selected = getValue();
-
- // Loop through choices
- for (int index = 0; index < choices.size(); index++)
- {
- // Get next choice
- final T choice = choices.get(index);
- appendOptionHtml(buffer, choice, index, selected);
- }
-
- // Replace body
- replaceComponentTagBody(markupStream, openTag, buffer);
+ return "";
}
/**
@@ -379,163 +358,90 @@ public class CheckBoxMultipleChoice<T> extends ListMultipleChoice<T>
* @param selected
* The currently selected string value
*/
- @SuppressWarnings("unchecked")
@Override
protected void appendOptionHtml(final AppendingStringBuffer buffer, final T choice, int index,
final String selected)
{
- Object displayValue = getChoiceRenderer().getDisplayValue(choice);
- Class<?> objectClass = displayValue == null ? null : displayValue.getClass();
- // Get label for choice
- String label = "";
- if (objectClass != null && objectClass != String.class)
- {
- @SuppressWarnings("rawtypes")
- IConverter converter = getConverter(objectClass);
- label = converter.convertToString(displayValue, getLocale());
- }
- else if (displayValue != null)
- {
- label = displayValue.toString();
- }
+ // Append option suffix
+ buffer.append(getPrefix(index, choice));
- // If there is a display value for the choice, then we know that the
- // choice is automatic in some way. If label is /null/ then we know
- // that the choice is a manually created checkbox tag at some random
- // location in the page markup!
- if (label != null)
- {
- // Append option suffix
- buffer.append(getPrefix(index, choice));
-
- String id = getChoiceRenderer().getIdValue(choice, index);
- final String idAttr = getCheckBoxMarkupId(id);
-
- // Add label for checkbox
- String display = label;
- if (localizeDisplayValues())
- {
- display = getLocalizer().getString(label, this, label);
- }
+ String id = getChoiceRenderer().getIdValue(choice, index);
+ final String idAttr = getCheckBoxMarkupId(id);
- final CharSequence escaped = (getEscapeModelStrings() ? Strings.escapeMarkup(display)
- : display);
+ CharSequence renderValue = renderValue(choice);
- // Allows user to add attributes to the <label..> tag
- IValueMap labelAttrs = getAdditionalAttributesForLabel(index, choice);
- StringBuilder extraLabelAttributes = new StringBuilder();
- if (labelAttrs != null)
+ // Allows user to add attributes to the <label..> tag
+ IValueMap labelAttrs = getAdditionalAttributesForLabel(index, choice);
+ StringBuilder extraLabelAttributes = new StringBuilder();
+ if (labelAttrs != null)
+ {
+ for (Map.Entry<String, Object> attr : labelAttrs.entrySet())
{
- for (Map.Entry<String, Object> attr : labelAttrs.entrySet())
- {
- extraLabelAttributes.append(' ')
- .append(Strings.escapeMarkup(attr.getKey()))
- .append("=\"")
- .append(Strings.escapeMarkup(attr.getValue().toString()))
- .append('"');
- }
+ extraLabelAttributes.append(' ')
+ .append(Strings.escapeMarkup(attr.getKey()))
+ .append("=\"")
+ .append(Strings.escapeMarkup(attr.getValue().toString()))
+ .append('"');
}
+ }
- switch (labelPosition)
- {
- case BEFORE:
- buffer.append("<label for=\"")
- .append(Strings.escapeMarkup(idAttr))
- .append('"')
- .append(extraLabelAttributes)
- .append('>')
- .append(escaped)
- .append("</label>");
- break;
- case WRAP_BEFORE:
- buffer.append("<label")
- .append(extraLabelAttributes)
- .append('>')
- .append(escaped)
- .append(' ');
- break;
- case WRAP_AFTER:
- buffer.append("<label")
- .append(extraLabelAttributes)
- .append('>');
- break;
- }
+ labelPosition.before(buffer, idAttr, extraLabelAttributes, renderValue);
- // Add checkbox element
- buffer.append("<input name=\"");
- buffer.append(getInputName());
- buffer.append('"');
- buffer.append(" type=\"checkbox\"");
- if (isSelected(choice, index, selected))
- {
- buffer.append(" checked=\"checked\"");
- }
- if (isDisabled(choice, index, selected) || !isEnabledInHierarchy())
- {
- buffer.append(" disabled=\"disabled\"");
- }
- buffer.append(" value=\"");
- buffer.append(Strings.escapeMarkup(id));
- buffer.append("\" id=\"");
- buffer.append(Strings.escapeMarkup(idAttr));
- buffer.append('"');
+ // Add checkbox element
+ buffer.append("<input name=\"");
+ buffer.append(getInputName());
+ buffer.append('"');
+ buffer.append(" type=\"checkbox\"");
+ if (isSelected(choice, index, selected))
+ {
+ buffer.append(" checked=\"checked\"");
+ }
+ if (isDisabled(choice, index, selected) || !isEnabledInHierarchy())
+ {
+ buffer.append(" disabled=\"disabled\"");
+ }
+ buffer.append(" value=\"");
+ buffer.append(Strings.escapeMarkup(id));
+ buffer.append("\" id=\"");
+ buffer.append(Strings.escapeMarkup(idAttr));
+ buffer.append('"');
- // Allows user to add attributes to the <input..> tag
+ // Allows user to add attributes to the <input..> tag
+ {
+ IValueMap attrs = getAdditionalAttributes(index, choice);
+ if (attrs != null)
{
- IValueMap attrs = getAdditionalAttributes(index, choice);
- if (attrs != null)
+ for (Map.Entry<String, Object> attr : attrs.entrySet())
{
- for (Map.Entry<String, Object> attr : attrs.entrySet())
- {
- buffer.append(' ')
- .append(Strings.escapeMarkup(attr.getKey()))
- .append("=\"")
- .append(Strings.escapeMarkup(attr.getValue().toString()))
- .append('"');
- }
+ buffer.append(' ')
+ .append(Strings.escapeMarkup(attr.getKey()))
+ .append("=\"")
+ .append(Strings.escapeMarkup(attr.getValue().toString()))
+ .append('"');
}
}
+ }
- DebugSettings debugSettings = getApplication().getDebugSettings();
- String componentPathAttributeName = debugSettings.getComponentPathAttributeName();
- if (Strings.isEmpty(componentPathAttributeName) == false)
- {
- CharSequence path = getPageRelativePath();
- path = Strings.replaceAll(path, "_", "__");
- path = Strings.replaceAll(path, ":", "_");
- buffer.append(' ').append(componentPathAttributeName).append("=\"")
- .append(path)
- .append("_input_")
- .append(index)
- .append('"');
- }
+ DebugSettings debugSettings = getApplication().getDebugSettings();
+ String componentPathAttributeName = debugSettings.getComponentPathAttributeName();
+ if (Strings.isEmpty(componentPathAttributeName) == false)
+ {
+ CharSequence path = getPageRelativePath();
+ path = Strings.replaceAll(path, "_", "__");
+ path = Strings.replaceAll(path, ":", "_");
+ buffer.append(' ').append(componentPathAttributeName).append("=\"")
+ .append(path)
+ .append("_input_")
+ .append(index)
+ .append('"');
+ }
- buffer.append("/>");
+ buffer.append("/>");
- switch (labelPosition)
- {
- case WRAP_BEFORE:
- buffer.append("</label>");
- break;
- case WRAP_AFTER:
- buffer.append(' ')
- .append(escaped)
- .append("</label>");
- break;
- case AFTER:
- buffer.append("<label for=\"")
- .append(Strings.escapeMarkup(idAttr))
- .append('"')
- .append(extraLabelAttributes)
- .append('>')
- .append(escaped)
- .append("</label>");
- break;
- }
+ labelPosition.after(buffer, idAttr, extraLabelAttributes, renderValue);
- // Append option suffix
- buffer.append(getSuffix(index, choice));
- }
+ // Append option suffix
+ buffer.append(getSuffix(index, choice));
}
/**
http://git-wip-us.apache.org/repos/asf/wicket/blob/263fcdc6/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java
index 3994204..60b6b27 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java
@@ -20,10 +20,8 @@ import java.util.List;
import java.util.Map;
import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.model.IModel;
import org.apache.wicket.settings.DebugSettings;
-import org.apache.wicket.util.convert.IConverter;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.AppendingStringBuffer;
import org.apache.wicket.util.string.Strings;
@@ -321,31 +319,12 @@ public class RadioChoice<T> extends AbstractSingleSelectChoice<T>
}
/**
- * @see org.apache.wicket.Component#onComponentTagBody(MarkupStream, ComponentTag)
+ * Not supported - does nothing.
*/
@Override
- public final void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
+ protected CharSequence getDefaultChoice(String selectedValue)
{
- // Iterate through choices
- final List<? extends T> choices = getChoices();
-
- // Buffer to hold generated body
- final AppendingStringBuffer buffer = new AppendingStringBuffer((choices.size() + 1) * 70);
-
- // The selected value
- final String selected = getValue();
-
- // Loop through choices
- for (int index = 0; index < choices.size(); index++)
- {
- // Get next choice
- final T choice = choices.get(index);
-
- appendOptionHtml(buffer, choice, index, selected);
- }
-
- // Replace body
- replaceComponentTagBody(markupStream, openTag, buffer);
+ return "";
}
/**
@@ -360,165 +339,86 @@ public class RadioChoice<T> extends AbstractSingleSelectChoice<T>
* @param selected
* The currently selected string value
*/
- @SuppressWarnings("unchecked")
@Override
protected void appendOptionHtml(final AppendingStringBuffer buffer, final T choice, int index,
final String selected)
{
- Object displayValue = getChoiceRenderer().getDisplayValue(choice);
- Class<?> objectClass = (displayValue == null ? null : displayValue.getClass());
-
- // Get label for choice
- String label = "";
-
- if (objectClass != null && objectClass != String.class)
- {
- @SuppressWarnings("rawtypes")
- final IConverter converter = getConverter(objectClass);
- label = converter.convertToString(displayValue, getLocale());
- }
- else if (displayValue != null)
- {
- label = displayValue.toString();
- }
-
- // If there is a display value for the choice, then we know that the
- // choice is automatic in some way. If label is /null/ then we know
- // that the choice is a manually created radio tag at some random
- // location in the page markup!
- if (label != null)
- {
- // Append option suffix
- buffer.append(getPrefix(index, choice));
+ // Append option suffix
+ buffer.append(getPrefix(index, choice));
- String id = getChoiceRenderer().getIdValue(choice, index);
- final String idAttr = getMarkupId() + "-" + id;
+ String id = getChoiceRenderer().getIdValue(choice, index);
+ final String idAttr = getMarkupId() + "-" + id;
- boolean enabled = isEnabledInHierarchy() && !isDisabled(choice, index, selected);
+ boolean enabled = isEnabledInHierarchy() && !isDisabled(choice, index, selected);
- // Add label for radio button
- String display = label;
- if (localizeDisplayValues())
- {
- display = getLocalizer().getString(label, this, label);
- }
+ CharSequence renderValue = renderValue(choice);
- CharSequence escaped = display;
- if (getEscapeModelStrings())
+ // Allows user to add attributes to the <label..> tag
+ IValueMap labelAttrs = getAdditionalAttributesForLabel(index, choice);
+ StringBuilder extraLabelAttributes = new StringBuilder();
+ if (labelAttrs != null)
+ {
+ for (Map.Entry<String, Object> attr : labelAttrs.entrySet())
{
- escaped = Strings.escapeMarkup(display);
+ extraLabelAttributes.append(' ')
+ .append(Strings.escapeMarkup(attr.getKey()))
+ .append("=\"")
+ .append(Strings.escapeMarkup(attr.getValue().toString()))
+ .append('"');
}
+ }
- // Allows user to add attributes to the <label..> tag
- IValueMap labelAttrs = getAdditionalAttributesForLabel(index, choice);
- StringBuilder extraLabelAttributes = new StringBuilder();
- if (labelAttrs != null)
+ labelPosition.before(buffer, idAttr, extraLabelAttributes, renderValue);
+
+ // Add radio tag
+ buffer.append("<input name=\"")
+ .append(getInputName())
+ .append('"')
+ .append(" type=\"radio\"")
+ .append((isSelected(choice, index, selected) ? " checked=\"checked\"" : ""))
+ .append((enabled ? "" : " disabled=\"disabled\""))
+ .append(" value=\"")
+ .append(Strings.escapeMarkup(id))
+ .append("\" id=\"")
+ .append(Strings.escapeMarkup(idAttr))
+ .append('"');
+
+ // Allows user to add attributes to the <input..> tag
+ {
+ IValueMap attrs = getAdditionalAttributes(index, choice);
+ if (attrs != null)
{
- for (Map.Entry<String, Object> attr : labelAttrs.entrySet())
+ for (Map.Entry<String, Object> attr : attrs.entrySet())
{
- extraLabelAttributes.append(' ')
- .append(Strings.escapeMarkup(attr.getKey()))
- .append("=\"")
- .append(Strings.escapeMarkup(attr.getValue().toString()))
- .append('"');
+ buffer.append(' ')
+ .append(Strings.escapeMarkup(attr.getKey()))
+ .append("=\"")
+ .append(Strings.escapeMarkup(attr.getValue().toString()))
+ .append('"');
}
}
+ }
- switch (labelPosition)
- {
- case BEFORE:
-
- buffer.append("<label for=\"")
- .append(Strings.escapeMarkup(idAttr))
- .append('"')
- .append(extraLabelAttributes)
- .append('>')
- .append(escaped)
- .append("</label>");
- break;
- case WRAP_BEFORE:
- buffer.append("<label")
- .append(extraLabelAttributes)
- .append('>')
- .append(escaped)
- .append(' ');
- break;
- case WRAP_AFTER:
- buffer.append("<label")
- .append(extraLabelAttributes)
- .append('>');
- break;
- }
-
- // Add radio tag
- buffer.append("<input name=\"")
- .append(getInputName())
- .append('"')
- .append(" type=\"radio\"")
- .append((isSelected(choice, index, selected) ? " checked=\"checked\"" : ""))
- .append((enabled ? "" : " disabled=\"disabled\""))
- .append(" value=\"")
- .append(Strings.escapeMarkup(id))
- .append("\" id=\"")
- .append(Strings.escapeMarkup(idAttr))
+ DebugSettings debugSettings = getApplication().getDebugSettings();
+ String componentPathAttributeName = debugSettings.getComponentPathAttributeName();
+ if (Strings.isEmpty(componentPathAttributeName) == false)
+ {
+ CharSequence path = getPageRelativePath();
+ path = Strings.replaceAll(path, "_", "__");
+ path = Strings.replaceAll(path, ":", "_");
+ buffer.append(' ').append(componentPathAttributeName).append("=\"")
+ .append(path)
+ .append("_input_")
+ .append(index)
.append('"');
+ }
- // Allows user to add attributes to the <input..> tag
- {
- IValueMap attrs = getAdditionalAttributes(index, choice);
- if (attrs != null)
- {
- for (Map.Entry<String, Object> attr : attrs.entrySet())
- {
- buffer.append(' ')
- .append(Strings.escapeMarkup(attr.getKey()))
- .append("=\"")
- .append(Strings.escapeMarkup(attr.getValue().toString()))
- .append('"');
- }
- }
- }
-
- DebugSettings debugSettings = getApplication().getDebugSettings();
- String componentPathAttributeName = debugSettings.getComponentPathAttributeName();
- if (Strings.isEmpty(componentPathAttributeName) == false)
- {
- CharSequence path = getPageRelativePath();
- path = Strings.replaceAll(path, "_", "__");
- path = Strings.replaceAll(path, ":", "_");
- buffer.append(' ').append(componentPathAttributeName).append("=\"")
- .append(path)
- .append("_input_")
- .append(index)
- .append('"');
- }
+ buffer.append("/>");
- buffer.append("/>");
+ labelPosition.after(buffer, idAttr, extraLabelAttributes, renderValue);
- switch (labelPosition)
- {
- case WRAP_BEFORE:
- buffer.append("</label>");
- break;
- case WRAP_AFTER:
- buffer.append(' ')
- .append(escaped)
- .append("</label>");
- break;
- case AFTER:
- buffer.append("<label for=\"")
- .append(Strings.escapeMarkup(idAttr))
- .append('"')
- .append(extraLabelAttributes)
- .append('>')
- .append(escaped)
- .append("</label>");
- break;
- }
-
- // Append option suffix
- buffer.append(getSuffix(index, choice));
- }
+ // Append option suffix
+ buffer.append(getSuffix(index, choice));
}
/**
http://git-wip-us.apache.org/repos/asf/wicket/blob/263fcdc6/wicket-core/src/test/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoiceTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoiceTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoiceTest.java
index cbf9a93..095da3a 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoiceTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoiceTest.java
@@ -128,7 +128,7 @@ public class CheckBoxMultipleChoiceTest extends WicketTestCase
tester.startPage(new TestPage(false, true, false, false));
tester.assertContains("<div wicket:id=\"checkWithFixedPrefix\">pre<input name=\"checkWithFixedPrefix\"");
tester.assertContains("</label>sufpre<input name=\"checkWithFixedPrefix\"");
- tester.assertContains("</label>suf</div>");
+ tester.assertContains("</label>suf\n</div>");
}
/** */
@@ -138,7 +138,7 @@ public class CheckBoxMultipleChoiceTest extends WicketTestCase
tester.startPage(new TestPage(false, false, true, false));
tester.assertContains("<div wicket:id=\"checkWithDynamicPrefix\">pre0a<input name=\"checkWithDynamicPrefix\"");
tester.assertContains("</label>suf0apre1b<input name=\"checkWithDynamicPrefix\"");
- tester.assertContains("</label>suf2c</div>");
+ tester.assertContains("</label>suf2c\n</div>");
}
@Test
@@ -165,7 +165,7 @@ public class CheckBoxMultipleChoiceTest extends WicketTestCase
};
tester.startComponentInPage(radioChoice);
- tester.assertResultPage("<span wicket:id=\"testid\"><input name=\"testid\" type=\"checkbox\" value=\"0\" id=\"testid1-testid_0\" class=\"input0\"/><label for=\"testid1-testid_0\" class=\"label0\">1</label></span>");
+ tester.assertResultPage("<span wicket:id=\"testid\"><input name=\"testid\" type=\"checkbox\" value=\"0\" id=\"testid1-testid_0\" class=\"input0\"/><label for=\"testid1-testid_0\" class=\"label0\">1</label>\n</span>");
}
@Test
@@ -186,7 +186,7 @@ public class CheckBoxMultipleChoiceTest extends WicketTestCase
radioChoice.setLabelPosition(AbstractChoice.LabelPosition.BEFORE);
tester.startComponentInPage(radioChoice);
- tester.assertResultPage("<span wicket:id=\"testid\"><label for=\"testid1-testid_0\" class=\"label0\">1</label><input name=\"testid\" type=\"checkbox\" value=\"0\" id=\"testid1-testid_0\" class=\"input0\"/></span>");
+ tester.assertResultPage("<span wicket:id=\"testid\"><label for=\"testid1-testid_0\" class=\"label0\">1</label><input name=\"testid\" type=\"checkbox\" value=\"0\" id=\"testid1-testid_0\" class=\"input0\"/>\n</span>");
}
@Test
@@ -207,7 +207,7 @@ public class CheckBoxMultipleChoiceTest extends WicketTestCase
radioChoice.setLabelPosition(AbstractChoice.LabelPosition.WRAP_BEFORE);
tester.startComponentInPage(radioChoice);
- tester.assertResultPage("<span wicket:id=\"testid\"><label class=\"label0\">1 <input name=\"testid\" type=\"checkbox\" value=\"0\" id=\"testid1-testid_0\" class=\"input0\"/></label></span>");
+ tester.assertResultPage("<span wicket:id=\"testid\"><label class=\"label0\">1 <input name=\"testid\" type=\"checkbox\" value=\"0\" id=\"testid1-testid_0\" class=\"input0\"/></label>\n</span>");
}
@Test
@@ -228,6 +228,6 @@ public class CheckBoxMultipleChoiceTest extends WicketTestCase
radioChoice.setLabelPosition(AbstractChoice.LabelPosition.WRAP_AFTER);
tester.startComponentInPage(radioChoice);
- tester.assertResultPage("<span wicket:id=\"testid\"><label class=\"label0\"><input name=\"testid\" type=\"checkbox\" value=\"0\" id=\"testid1-testid_0\" class=\"input0\"/> 1</label></span>");
+ tester.assertResultPage("<span wicket:id=\"testid\"><label class=\"label0\"><input name=\"testid\" type=\"checkbox\" value=\"0\" id=\"testid1-testid_0\" class=\"input0\"/> 1</label>\n</span>");
}
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/263fcdc6/wicket-core/src/test/java/org/apache/wicket/markup/html/form/RadioChoiceTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/RadioChoiceTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/RadioChoiceTest.java
index f47f043..c5e4897 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/RadioChoiceTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/RadioChoiceTest.java
@@ -29,7 +29,7 @@ public class RadioChoiceTest extends WicketTestCase
RadioChoice<Integer> radioChoice = new RadioChoice<Integer>("testid", Arrays.asList(1));
tester.startComponentInPage(radioChoice);
- tester.assertResultPage("<span wicket:id=\"testid\"><input name=\"testid\" type=\"radio\" value=\"0\" id=\"testid1-0\"/><label for=\"testid1-0\">1</label></span>");
+ tester.assertResultPage("<span wicket:id=\"testid\"><input name=\"testid\" type=\"radio\" value=\"0\" id=\"testid1-0\"/><label for=\"testid1-0\">1</label>\n</span>");
}
@Test
@@ -39,7 +39,7 @@ public class RadioChoiceTest extends WicketTestCase
radioChoice.setLabelPosition(AbstractChoice.LabelPosition.BEFORE);
tester.startComponentInPage(radioChoice);
- tester.assertResultPage("<span wicket:id=\"testid\"><label for=\"testid1-0\">1</label><input name=\"testid\" type=\"radio\" value=\"0\" id=\"testid1-0\"/></span>");
+ tester.assertResultPage("<span wicket:id=\"testid\"><label for=\"testid1-0\">1</label><input name=\"testid\" type=\"radio\" value=\"0\" id=\"testid1-0\"/>\n</span>");
}
@Test
@@ -49,7 +49,7 @@ public class RadioChoiceTest extends WicketTestCase
radioChoice.setLabelPosition(AbstractChoice.LabelPosition.WRAP_BEFORE);
tester.startComponentInPage(radioChoice);
- tester.assertResultPage("<span wicket:id=\"testid\"><label>1 <input name=\"testid\" type=\"radio\" value=\"0\" id=\"testid1-0\"/></label></span>");
+ tester.assertResultPage("<span wicket:id=\"testid\"><label>1 <input name=\"testid\" type=\"radio\" value=\"0\" id=\"testid1-0\"/></label>\n</span>");
}
@Test
@@ -59,6 +59,6 @@ public class RadioChoiceTest extends WicketTestCase
radioChoice.setLabelPosition(AbstractChoice.LabelPosition.WRAP_AFTER);
tester.startComponentInPage(radioChoice);
- tester.assertResultPage("<span wicket:id=\"testid\"><label><input name=\"testid\" type=\"radio\" value=\"0\" id=\"testid1-0\"/> 1</label></span>");
+ tester.assertResultPage("<span wicket:id=\"testid\"><label><input name=\"testid\" type=\"radio\" value=\"0\" id=\"testid1-0\"/> 1</label>\n</span>");
}
}