In a legacy code base, I came across this:
@javax.faces.convert.FacesConverter(forClass = java.lang.String.class)
public class WhitespaceToNullConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent c, String value) {
if (value == null || value.trim().isEmpty()) {
if (c instanceof EditableValueHolder) {
((EditableValueHolder) c).setSubmittedValue(null);
}
return null;
}
return value;
}
// ...
}
First, isn't the passed UIComponent
always an EditableValueHolder
? Is that check needed?
Second, should a Converter
change the UIComponent
it's called for? That seems odd to me, assuming that the component's value is probably used to populate the UIComponent
anyway.
The JavaDoc doesn't say anything in that regard.