【发布时间】:2011-06-17 15:18:24
【问题描述】:
我正在尝试使用rich:calendar,当日期属性selectedDate 和currentDate 是Date 类型时它可以工作。当我使用Calendar 时,它不起作用。
当我提交表单时,它会报告:
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/PORTAL] threw exception [javax.el.ELException: /test.xhtml @58,36 value="#{bean.calendar.selectedDate}": Cannot convert 24.6.11 0:00 of type class java.util.Date to class java.util.Calendar] with root cause
javax.el.ELException: /test.xhtml @58,36 value="#{bean.calendar.selectedDate}": Cannot convert 24.6.11 0:00 of type class java.util.Date to class java.util.Calendar
我的 XHTML:
<rich:calendar
mode="ajax" id="calendar"
value="#{bean.calendar.selectedDate}"
locale="#{calendarBean.locale}"
datePattern="#{calendarBean.pattern}"
required="true">
</rich:calendar>
还有日历豆:
@ManagedBean
public class CalendarBean
{
private Calendar currentDate;
private Calendar selectedDate;
public Calendar getCurrentDate() {
return currentDate;
}
public void setCurrentDate(Calendar currentDate) {
this.currentDate = currentDate;
}
public Calendar getSelectedDate() {
return selectedDate;
}
public void setSelectedDate(Calendar selectedDate) {
this.selectedDate = selectedDate;
}
我做错了什么?
【问题讨论】:
-
@mre:这毫无意义。在使用公历的语言环境中,
Calendar是GregorianCalendar已经。再看,Calendar是一个接口。您可以通过System.out.println(Calendar.getInstance().getClass())找到您的Calendar类的具体实现。所有其他实现的行为不应有所不同。 -
@BalusC,嗯..我想我明白你在说什么。我建议
GregorianCalendar,因为它是一个类,而不是一个接口。如果不正确,我会删除我的建议。 :) -
@mre:多研究一下接口和多态性。玩一会儿 JDBC 和不同的 DB,直到你最终意识到接口的力量。