I am using Java Server Faces to develop a dynamic application form. (developing on RAD/Websphere).
I have a 'Customer' backing bean with a dateOfBirth field of type java.util.Calendar
I have a problem where I have written a custom converter to convert a String input to Calendar object and this seems to work ok. The problem arises when the form fails validation. The field displays back the full Calendar object instead of displaying as a String. Do I need to change my converter or the way I call the value in the backing bean?
Converter code:-
public class DateConverter implements Converter {
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (StringUtility.isStringEmp
ty(value))
{ return null;}
String sDate = value.replaceAll("[a-z,A-Z
, ,-,,/]+","");
String day = sDate.substring(0,2);
String month = sDate.substring(2,4);
String year = sDate.substring(4);
Calendar dateOfBirth = Calendar.getInstance();
dateOfBirth.set(Integer.pa
rseInt(yea
r),Integer
.parseInt(
month),Int
eger.parse
Int(day));
return dateOfBirth;
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
return value.toString();
}
}
Start Free Trial