You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Leonardo Uribe (Commented) (JIRA)" <de...@myfaces.apache.org> on 2012/03/15 23:04:37 UTC

[jira] [Commented] (TOMAHAWK-1613) HtmlCalendarRenderer Throws ClassCastException - not fixed

    [ https://issues.apache.org/jira/browse/TOMAHAWK-1613?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13230609#comment-13230609 ] 

Leonardo Uribe commented on TOMAHAWK-1613:
------------------------------------------

Some time ago I studied in deep the problem. Really the problem to deal with different date types was solved in TOMAHAWK-1508. I'll take some extracts from that issue to explain it to you:

"... I reviewed both components and the problem for use Converter interface reside in its design vs t:inputCalendar and t:inputDate requeriments. It has two problems:

- It assume submittedValue is always a String, but for t:inputDate that is not true. For this case as suggested, we need a property to give the chance to convert the java.util.Date instance used by the component to other type and viceversa.

- t:inputCalendar and t:inputDate requires a base "date type" to manipulate. In both cases is java.util.Date, but the boundaries between the base date type and the business type are not clear. For example, in jdk 1.6 java.sql.Date that extends from java.util.Date override some methods and makes t:inputCalendar and t:inputDate fail.  ...."

In few words, t:inputDate and t:inputCalendar cannot know all different date types and manipulate them correctly. But we needed some flexibility on the model to use different date types (plain String, Calendar or use joda library for date/time).

Unfortunately the Converter interface is not good enough, because it does not isolate correctly the value in the model and the one used by t:inputDate/t:inputCalendar to render itself. There are some "corner cases" that make it fail.

The right way to do it is introduce a proper converter interface to deal with the conversion between the value stored in the bean and the value used by t:inputCalendar / t:inputDate. That is org.apache.myfaces.custom.calendar.DateBusinessConverter

"... Provide a bridge between the java.util.Date instance used by a component that receive date/time values and
the "business" value used to represent the value. ..."

So, instead use a custom converter, try adding this class:

package myproject.myconverter;

public class CalendarDateBusinessConverter implements DateBusinessConverter
{

    public Object getBusinessValue(FacesContext context,
                       UIComponent component,
                       java.util.Date value)
    {
        // ... convert from java.util.Date to Calendar
        return calendarValue;
    }

    public java.util.Date getDateValue(FacesContext context,
                       UIComponent component,
                       Object value)
    {
       // ... convert from Calendar to java.util.Date
       return dateValueToUseByDateComponent;
    }

}

And register the class

<t:inputCalendar dateBusinessConverter="myproject.myconverter.CalendarDateBusinessConverter"

It also receive EL expressions. Anyway, I'll remove the cast for the next version.
                
> HtmlCalendarRenderer Throws ClassCastException - not fixed
> ----------------------------------------------------------
>
>                 Key: TOMAHAWK-1613
>                 URL: https://issues.apache.org/jira/browse/TOMAHAWK-1613
>             Project: MyFaces Tomahawk
>          Issue Type: Bug
>    Affects Versions: 1.1.11
>            Reporter: Klaus Schuster
>
> The problem mentioned TOMAHAWK-1599 is not fixed.
> I could locally fix the problem with changing line 169 in File:
> org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java
> from:
>                 value = (Date) inputCalendar.getValue();
> to:
> if(converter instanceof DateConverter) {
>                value = ((DateConverter) converter).getAsDate(facesContext, inputCalendar);
>            } else {
>                value = (Date) inputCalendar.getValue();
>            } 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira