Www.manorrock.com / Online / Blogs Login
Introduction to JSF Converters | Main | The NumberConverter

JSF

The JSF Converter API

9/21/2012 7:09 PM
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 method 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!

Comments

2 points: 1, name, it has return value, get duplicated it means of action. java man know it. some most preference maybe toX, or asX for c guys. 2, parameters, 3, do you real think it necessary? dont' think about it for me, I hope the parameter just present on my demand. so maybe asX(Context, string). or interface{ context(); asX(string);}

Add a comment
Up

Copyright © 2002-2013 Manorrock.com. All Rights Reserved.