PAQed with points refunded (500)
Computer101
EE Admin
Main Topics
Browse All TopicsI 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
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
return dateOfBirth;
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
return value.toString();
}
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: paulmakerPosted on 2007-07-16 at 06:16:19ID: 19495163
Doe!
ty(value)) { return null;}
, ,-,,/]+",""); rseInt(yea r),Integer .parseInt( month),Int eger.parse Int(day));
ar.getTime ());
Fixed it myself. Converter code...
public class DateConverter implements Converter {
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (StringUtility.isStringEmp
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
return dateOfBirth;
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
String displayDate = "";
if(value!=null){
Calendar calendar = (Calendar)value;
SimpleDateFormat fSDateFormat = new SimpleDateFormat ("d mm yyyy");
displayDate = fSDateFormat.format(calend
}
return displayDate;
}
}
Still needs a tweak for display but sorted anyway.