JSP Radiobutton/CheckboxesTag utilizes PropertyEditor/ConversionService for label rendering (SPR-7174)

This commit is contained in:
Juergen Hoeller 2010-05-13 23:07:11 +00:00
parent ceb668ac6c
commit 8ccd74b6c8
3 changed files with 14 additions and 6 deletions

View File

@ -16,7 +16,6 @@
package org.springframework.web.servlet.tags.form; package org.springframework.web.servlet.tags.form;
import java.beans.PropertyEditor;
import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspException;
/** /**
@ -45,8 +44,7 @@ public abstract class AbstractCheckedElementTag extends AbstractHtmlInputElement
* bound value. * bound value.
*/ */
protected void renderFromValue(Object item, Object value, TagWriter tagWriter) throws JspException { protected void renderFromValue(Object item, Object value, TagWriter tagWriter) throws JspException {
PropertyEditor editor = (value != null ? getBindStatus().findEditor(value.getClass()) : null); tagWriter.writeAttribute("value", convertToDisplayString(value));
tagWriter.writeAttribute("value", getDisplayString(value, editor));
if (isOptionSelected(value) || (value != item && isOptionSelected(item))) { if (isOptionSelected(value) || (value != item && isOptionSelected(item))) {
tagWriter.writeAttribute("checked", "checked"); tagWriter.writeAttribute("checked", "checked");
} }

View File

@ -218,6 +218,16 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im
return getPropertyEditor(); return getPropertyEditor();
} }
/**
* Get a display String for the given value, converted by a PropertyEditor
* that the BindStatus may have registered for the value's Class.
*/
protected String convertToDisplayString(Object value) throws JspException {
PropertyEditor editor = (value != null ? getBindStatus().findEditor(value.getClass()) : null);
return getDisplayString(value, editor);
}
/** /**
* Disposes of the {@link BindStatus} instance. * Disposes of the {@link BindStatus} instance.
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -228,7 +228,7 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem
} }
} }
else { else {
throw new IllegalArgumentException("Attribute 'items' must be a Collection, an Array or a Map"); throw new IllegalArgumentException("Attribute 'items' must be an array, a Collection or a Map");
} }
return SKIP_BODY; return SKIP_BODY;
@ -286,7 +286,7 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem
tagWriter.endTag(); tagWriter.endTag();
tagWriter.startTag("label"); tagWriter.startTag("label");
tagWriter.writeAttribute("for", id); tagWriter.writeAttribute("for", id);
tagWriter.appendValue(label.toString()); tagWriter.appendValue(convertToDisplayString(label));
tagWriter.endTag(); tagWriter.endTag();
tagWriter.endTag(); tagWriter.endTag();
} }