Skip to content

Instantly share code, notes, and snippets.

@struberg
Created October 23, 2014 14:13
Show Gist options
  • Save struberg/459ccc234cea01edc89b to your computer and use it in GitHub Desktop.
Save struberg/459ccc234cea01edc89b to your computer and use it in GitHub Desktop.
@FacesConverter(forClass = String.class)
public class StringConverter implements Converter{
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
if (component instanceof HtmlInputText || component instanceof HtmlInputTextarea) {
return (value != null) ? StringUtils.trimToNull(value) : null;
}
return value;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException {
return (value != null) ? value.toString() : null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment