<rich:calendar>不接受java.util.Calendar </rich:calendar>

时间:2011-06-17 15:18:24

标签: java jsf richfaces

我正在尝试使用rich:calendar,当日期属性selectedDatecurrentDateDate类型时,它会起作用。当我使用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>

和日历bean

@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;  
  }

我做错了什么?

1 个答案:

答案 0 :(得分:4)

Calendar类的time属性代表java.util.Date,其中包含gettersetter。利用它。

value="#{bean.calendar.selectedDate.time}"