我正在使用丰富的日历,在网页中我应该有日历,但是 bean 属性是一个字符串,我无法将其更改为日期,但在保存表单期间我总是有
java.text.ParseException: Unparseable date: "Tue Dec 09 00:00:00 GMT+04:00 2059"
java.text.DateFormat.parse(DateFormat.java:357)
javax.faces.convert.DateTimeConverter.getAsObject(DateTimeConverter.java:398)
org.richfaces.component.UICalendar.getAsDate(UICalendar.java:399)
org.richfaces.renderkit.CalendarRendererBase.getSelectedDate(CalendarRendererBase.java:658)
org.richfaces.renderkit.html.CalendarRenderer.doEncodeEnd(CalendarRenderer.java:451)
org.richfaces.renderkit.html.CalendarRenderer.doEncodeEnd(CalendarRenderer.java:516)
org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:134)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:242)
我尝试了很多,但没有任何转换器帮助...
任何想法?
这是一个转换器
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
String pattern = "yyyy-MM-dd, HH:mm:ss aaa";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Date nDate = null;
if (value == null || value.trim().length() == 0) {
return nDate;
}
try {
nDate = sdf.parse(value);
} catch (ParseException ex) {
}
return nDate;
}
@Override
public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object value) {
String date = "";
try{
if (value == null) {
return "";
}
String pattern = "yyyy-MM-dd, HH:mm:ss aaa";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Date dateValue = new SimpleDateFormat("yyyy-MM-dd, HH:mm:ss aaa", Locale.ENGLISH).parse(value.toString());
date = sdf.format((Date) dateValue);
}
catch(Exception e){
e.printStackTrace();
}
return date;
}
but it does not work