Hi guys,
I have the same environment as Daniel. I think this is a bug in PrimeFaces. I have a similar method in my utility class, but a little bit different. There is a lot of example how to get a converter in a proper way. I do it as follows:
Code: Select all
/**
* Returns converter {@link Converter} to the given component. Only components implemented
* {@link EditableValueHolder} have a converter.
*
* @param context current faces context
* @param component UIComponent
* @return Converter converter {@link Converter} or <code>null</code>
*/
public static Converter getConverter(final FacesContext context, final UIComponent component)
{
if (!(component instanceof EditableValueHolder)) {
return null;
}
Converter converter = ((EditableValueHolder) component).getConverter();
if (converter != null) {
return converter;
}
ValueExpression valueExpression = component.getValueExpression("value");
if (valueExpression == null) {
return null;
}
Class<?> converterType = valueExpression.getType(context.getELContext());
if (converterType == null
|| converterType == String.class
|| converterType == Object.class) {
// no conversation is needed
return null;
}
return context.getApplication().createConverter(converterType);
}
and now how PrimeFaces does it in InputTextRenderer
Code: Select all
@Override
public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException {
InputText inputText = (InputText) component;
String value = (String) submittedValue;
Converter converter = inputText.getConverter();
//first ask the converter
if(converter != null) {
return converter.getAsObject(context, inputText, value);
}
//Try to guess
else {
ValueExpression ve = inputText.getValueExpression("value");
if(ve != null) {
Class<?> valueType = ve.getType(context.getELContext());
Converter converterForType = context.getApplication().createConverter(valueType);
if(converterForType != null) {
return converterForType.getAsObject(context, inputText, value);
}
}
}
return value;
}
You see,
context.getApplication().createConverter(valueType) is always called if even no conversion is needed (see my check for converterType). valueType is null in your case. Therefore, a check valueType (null or String.class, Object.class) is quite important.
You can create an issue if it's really an issue. Actually, Cagatay, I would write / move the method
getConverter(final FacesContext context, final UIComponent component) to ComponentUtils or whatever PrimeFaces has.