How do I map the IceFaces <ice: selectInputDate> component to a java.util.Calendar field?

Does anyone know how one can map a component <ice:selectInputDate>

to a field java.util.Calendar

instead of java.util.Date

?

I am using IceFaces version 1.8.2, component <ice:selectInputDate>

. This component requires binding with java.util.Date

proeprty. For example, the value="#{bean.myDate}"

field myDate

must be of type java.util.Date

. But I need my date field to be of type java.util.Calendar

.

My trials: I tried using a standard converter or a custom one:

  • Standard: <f:convertDateTime pattern="dd/MM/yyyy" />

    It formats the correct value in the GUI, but when setting it in the bean.myDate

    type property , I Calendar

    get the following error message:

    [5/3/10 12: 09: 18: 398 EEST] 00000021 lifecycle i WARNING: FacesMessage (s) have been queued but may not have. sourceId = j_id12: j_id189: myDate [severity = (ERROR 2), summary = (/ WEB-INF / xhtml ............ file.xhtml @ 507.51 value = "# {bean. myDate} ": Cannot set property 'myDate' on class 'bean' to evaluate to" 5/11/10 3:00 AM ".), detail = (/ WEB-INF / XHTML ........ file .xhtml @ 507.51 value = "# {bean.myDate}": Unable to set property 'myDate' on class "... bean ..." to evaluate "5/11/10 3:00 AM.)]

  • Custom: <f:converter converterId="c2d"/>

    • getAsObject - Returns the object java.util.Calendar

      from the dispatched one String

      .
    • getAsString - gets Object

      and returns the format String

      .

NOTE. This method was hacked, so instead of waiting java.util.Calendar

, the method was extended getAsObject

. Instead, the cracked method getAsString

expects java.util.Date

, supplied as a parameter (via ice:selectInputDate

) and returns String

in the format.

But still the error message appears:

[5/3/10 12: 55: 34: 299 EEST] 0000001f D2DFaceletVie E com.icesoft.faces.facelets.D2DFaceletViewHandler renderResponse RenderResponse issue: java.util.GregorianCalendar incompatible with java.util.Date java.lang.ClassCastException java.util.GregorianCalendar is incompatible with java.util.Date at com.icesoft.faces.component.selectinputdate.SelectInputDate.getTextToRender (SelectInputDate.java:252)

Any hints are very helpful! Thanks, Michaela

+2


a source to share


2 answers


Wrap the property with Calendar

another getter / setter return / getter Date

.

private Calendar calendar;

public Date getCalendarDate() {
    return (calendar != null) ? calendar.getTime() : null;
}

public void setCalendarDate(Date date) {
    if (calendar == null) {
        calendar = Calendar.getInstance();
        calendar.clear(); // Avoid timezone issues.
    }
    calendar.setTime(date);
}

      



A JSF converter won't work because it only does conversions Object

String

, whereas we need a conversion Object

Date

. I'm not doing IceFaces, but there might be a chance that a particular component will accept a date string in a particular format pattern. You will need to find this and then write a covnerter to convert Calendar

String

to match this string format pattern. java.text.SimpleDateFormat

useful in this.

+4


a source


Either do as BalusC suggests, or just install value="#{yourBean.yourCalendar.time}

.



+3


a source







All Articles