Skip to content

Commit 8ccd74b

Browse files
committed
JSP Radiobutton/CheckboxesTag utilizes PropertyEditor/ConversionService for label rendering (SPR-7174)
1 parent ceb668a commit 8ccd74b

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/AbstractCheckedElementTag.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.web.servlet.tags.form;
1818

19-
import java.beans.PropertyEditor;
2019
import javax.servlet.jsp.JspException;
2120

2221
/**
@@ -45,8 +44,7 @@ protected void renderFromValue(Object value, TagWriter tagWriter) throws JspExce
4544
* bound value.
4645
*/
4746
protected void renderFromValue(Object item, Object value, TagWriter tagWriter) throws JspException {
48-
PropertyEditor editor = (value != null ? getBindStatus().findEditor(value.getClass()) : null);
49-
tagWriter.writeAttribute("value", getDisplayString(value, editor));
47+
tagWriter.writeAttribute("value", convertToDisplayString(value));
5048
if (isOptionSelected(value) || (value != item && isOptionSelected(item))) {
5149
tagWriter.writeAttribute("checked", "checked");
5250
}

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/AbstractDataBoundFormElementTag.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ public final PropertyEditor getEditor() throws JspException {
218218
return getPropertyEditor();
219219
}
220220

221+
/**
222+
* Get a display String for the given value, converted by a PropertyEditor
223+
* that the BindStatus may have registered for the value's Class.
224+
*/
225+
protected String convertToDisplayString(Object value) throws JspException {
226+
PropertyEditor editor = (value != null ? getBindStatus().findEditor(value.getClass()) : null);
227+
return getDisplayString(value, editor);
228+
}
229+
230+
221231
/**
222232
* Disposes of the {@link BindStatus} instance.
223233
*/

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/AbstractMultiCheckedElementTag.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -228,7 +228,7 @@ else if (itemsObject instanceof Map) {
228228
}
229229
}
230230
else {
231-
throw new IllegalArgumentException("Attribute 'items' must be a Collection, an Array or a Map");
231+
throw new IllegalArgumentException("Attribute 'items' must be an array, a Collection or a Map");
232232
}
233233

234234
return SKIP_BODY;
@@ -286,7 +286,7 @@ private void writeElementTag(TagWriter tagWriter, Object item, Object value, Obj
286286
tagWriter.endTag();
287287
tagWriter.startTag("label");
288288
tagWriter.writeAttribute("for", id);
289-
tagWriter.appendValue(label.toString());
289+
tagWriter.appendValue(convertToDisplayString(label));
290290
tagWriter.endTag();
291291
tagWriter.endTag();
292292
}

0 commit comments

Comments
 (0)