JSF Tip #13 - The JSF Converter API
Note this blog is obsolete, see https://www.manorrock.com/blog/ for the current blog
See what the JSF Validator API is about!
The definition of a Converter according to the Converter interface:
Object getAsObject(FacesContext context, UIComponent component, String value)
String getAsString(FacesContext context, UIComponent component, Object value)
The Faces Context is passed in so the converter can introspect various aspects of the request and response. The UI component is passed in so you can access the actual component that the conversion is done for.
In the getAsObject method the value passed in is a String since it is the value coming from the browser and the method will convert that to a domain specific object that you need.
In the getAsString method the value passed in is an Object since the domain specific object now need to be converted to something (a string) the browser understands.
Both methods throws a ConverterException when the conversion fails. So if you want the request life cycle to terminate early this method needs to throw the ConverterException.
That's all for this blog entry, see you soon!