|
Thank you for answer, Mike. I'm still not sure, weather the second part is really an unrelated spec issue because it could be just the consequence of the first one. So I've decide to describe both together thinking, it can help during code review since it belongs to very common part of core implementation (org.apache.myfaces.shared.renderkit.RendererUtils). If my suggestion is wrong, the second part can be just ignored. Please see also my comment to MYFACES-1452, which was the start point of my 'investigation' :) I've tried to solve the problem myself, but it was just a partially solution for me (respectively to second part of MYFACES-1532 description). Since no one has answered in mailing list, I've thinking my suggestion is just wrong and haven't provide this as path. But if I'm right, the same should affect other standard types too (i.e. Date etc.) Anyway, here's my code. This method is intended to replace existing getBooleanValue() in org.apache.myfaces.shared.renderkit.RendererUtils, which is called from org.apache.myfaces.shared.renderkit.html.HtmlCheckboxRendererBase.encodeEnd(). public static Boolean getBooleanValueForCheckbox(FacesContext facesContext,
UIComponent component) {
Object value = getObjectValue(component);
// This call relays on the implementation of getObjectValue()!!!
// If uiComponent is not an instance of ValueHolder, the
// IllegalArgumentException should be already thrown.
Converter converter = ((ValueHolder) component).getConverter();
if (null == value || value instanceof Boolean) {
return (Boolean) value;
}
if (null == converter && value instanceof String) {
// it's still correct to convert String into Boolean, because
// Boolean provides constructor Boolean(String x)!
return new Boolean(value.toString());
}
// If component provides no custom converter, we
// must try to obtain a standard one from Application
if (null == converter) {
try {
converter = facesContext.getApplication().createConverter(
value.getClass());
} catch (FacesException ex) {
throw new IllegalArgumentException("Component : "
+ getPathToComponent(component)
+ " expects value of type Boolean.\n"
+ "Neither standard converter for "
+ value.getClass().getName()
+ " nor custom converter provided.");
}
}
if (null != converter) {
try {
/* Try to convert it into String. That is!
* The getAsObject() provides the conversion of string value's
* representation into custom user type. We are expecting a Boolean,
* but the value itself is not a Boolean, so we need to get String first.
*/
String strValue = converter.getAsString(facesContext,
component, value);
boolean warn = (null == strValue);
warn = warn
|| !(strValue.equalsIgnoreCase(Boolean.TRUE.toString()) || strValue
.equalsIgnoreCase(Boolean.TRUE.toString()));
if (warn) {
/* Note that this situation is not an error! We have some
* converter and it got back some string, and no exception has been
* thrown!
*/
log.warn("Component "
+ getPathToComponent(component)
+ " expects value of type Boolean. The value was converted with "
+ converter.getClass().getName()
+ " into "
+ strValue
+ ", what is neither true nor false! false assumed.");
}
return new Boolean(strValue);
} catch (ConverterException ex) {
throw new IllegalArgumentException("Component : "
+ getPathToComponent(component)
+ " expects value of type Boolean.\n"
+ "Unable to convert " + value.getClass().getName()
+ " into Boolean.");
}
} else {
throw new IllegalArgumentException("Component "
+ getPathToComponent(component)
+ " expects value of type Boolean but "
+ value.getClass().getName() + " was found.");
}
}
regards, paul Mike Kienenberger schrieb: On 2/27/07, Paul Iov <[EMAIL PROTECTED]> wrote: |
- Re: MYFACES-1545 / MYFACES-1532 Paul Iov
- Re: MYFACES-1545 / MYFACES-1532 Mike Kienenberger
- Re: MYFACES-1545 / MYFACES-1532 Paul Iov
- Re: MYFACES-1545 / MYFACES-1532 Martin Marinschek
- Re: MYFACES-1545 / MYFACES-1532 Paul Iov
- Re: MYFACES-1545 / MYFACES-1532 Martin Marinschek
- Re: MYFACES-1545 / MYFACES-153... Paul Iov
- Re: MYFACES-1545 / MYFACES-153... Paul Iov

