Hi,
In practice, what we often do in Converters and Validators is something
like the following:
@FacesConverter("toLowerCaseConverter")
public class ToLowerCaseConverter implements Converter<String> {
@Override
public String getAsObject(FacesContext context, UIComponent component,
String value) {
if (value == null) {
return null;
}
return value.toLowerCase(getLocale());
}
@Override
public String getAsString(FacesContext context, UIComponent component,
String value) {
return value;
}
}
The null check is pretty repetitive.
What about:
@FacesConverter("toLowerCaseConverter", nullSafe= true)
public class ToLowerCaseConverter implements Converter<String> {
@Override
public String getAsObject(FacesContext context, UIComponent component,
String value) {
return value.toLowerCase(getLocale());
}
@Override
public String getAsString(FacesContext context, UIComponent component,
String value) {
return value;
}
}
The nullSafe=true would let the runtime do the == null return null thing
(for both methods, the example only shows one).
Thoughts?
Kind regards,
Arjan Tijms