This content has been marked as final.
Show 2 replies
-
1. Re: rich:calendar doesnt accept java.util.Calendar in 3.1.3
fabmars Mar 24, 2008 11:35 AM (in response to shivdeepk)There are other topis about it, including one i opened 8 months ago when rich calendar was released. And despite all that was said, i can assure you: rich:calendar doesn't accept Calendar's.
Personnally I made a converter.public class CalendarConverter implements Converter { public Object getAsObject(FacesContext context, UIComponent component, String value) { Calendar cal = null; if(!StringUtils.isEmpty(value)) { Locale locale = (Locale)((UICalendar)component).getLocale(); String pattern = ((UICalendar)component).getDatePattern(); DateFormat df = new SimpleDateFormat(pattern, locale); try { Date date = df.parse(value); cal = new GregorianCalendar(); cal.setTime(date); } catch(ParseException e) { throw new ConverterException(e); } } return cal; } public String getAsString(FacesContext context, UIComponent component, Object value) { String result = null; if(value != null) { if(value instanceof String) { result = (String)value; } else { DateFormat df; if(component instanceof UICalendar) { Locale locale = (Locale)((UICalendar)component).getLocale(); String pattern = ((UICalendar)component).getDatePattern(); df = new SimpleDateFormat(pattern, locale); } else { Locale locale = context.getViewRoot().getLocale(); df = DateFormat.getDateInstance(DateFormat.DEFAULT, locale); } Date date = ((Calendar)value).getTime(); result = df.format(date); } } return result; } }
-
2. Re: rich:calendar doesnt accept java.util.Calendar in 3.1.3
shivdeepk Apr 1, 2008 10:03 AM (in response to shivdeepk)Thanks for the code!