[ 
http://issues.apache.org/jira/browse/MYFACES-1023?page=comments#action_12366768 
] 

Mario Ivankovits commented on MYFACES-1023:
-------------------------------------------

I think the problem with the joda converter is it do not implement the 
DateConverter (also introduced by me ;) ) interface.


For the inputCalender thing I use a simpler converter:

package com.ops.OPSJ.jsflib;

import java.util.Date;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import org.apache.myfaces.custom.calendar.HtmlCalendarRenderer;
import org.apache.myfaces.renderkit.RendererUtils;
import org.joda.time.DateTime;

public class DateTimeConverter extends 
HtmlCalendarRenderer.CalendarDateTimeConverter
{
        public Object getAsObject(FacesContext facesContext, UIComponent 
uiComponent, String s)
        {
                Date date = (Date) super.getAsObject(facesContext, uiComponent, 
s);
                if (date == null)
                {
                        return null;
                }
                
                return new DateTime(date);
        }

        public Date getAsDate(FacesContext facesContext, UIComponent 
uiComponent)
        {
                Object value = RendererUtils.getObjectValue(uiComponent);
                if (value instanceof DateTime)
                {
                        return ((DateTime) value).toDate();
                }

                throw new IllegalArgumentException("Expected submitted value of 
type DateTime for component : "
                        +RendererUtils.getPathToComponent(uiComponent));
        }

        public String getAsString(FacesContext facesContext, UIComponent 
uiComponent, Object o)
        {
                if (o == null)
                {
                        return null;
                }

                if (o instanceof String)
                {
                        return (String) o;
                }

                Date date;
                if (o instanceof Date)
                {
                        date = (Date) o;
                }
                else
                {
                        date = ((DateTime) o).toDate();
                }

                return super.getAsString(facesContext, uiComponent, date);
        }
}


> inputCalendar with CalendarConverter loses value data
> -----------------------------------------------------
>
>          Key: MYFACES-1023
>          URL: http://issues.apache.org/jira/browse/MYFACES-1023
>      Project: MyFaces
>         Type: Bug
>   Components: Tomahawk
>     Versions: 1.1.1
>  Environment: windows xp pro
>     Reporter: Sven Vogt

>
> When I set a Converter for java.util.Calendar to inputCalendar, the value 
> will not be rendered.
> <t:inputCalendar id="calendar_1"
>                value="#{exampleInputBean.calendar}"
>                renderAsPopup="true">
>       <f:converter converterId="de.orgaplan.faces.CalendarConverter" />
> </t:inputCalendar>
> Because the HtmlCalendarRenderer throws an IllegalArgumentException and set 
> the value to null.
> My Converter is not an Instance of DateConverter.
>         Date value;
>         try
>         {
>             // value = RendererUtils.getDateValue(inputCalendar);
>             Converter converter = getConverter(inputCalendar);
>             if (converter instanceof DateConverter)
>             {
>                 value = ((DateConverter) converter).getAsDate(facesContext, 
> component);
>             }
>             else
>             {
>                 value = RendererUtils.getDateValue(inputCalendar);
>             }
>               }
>         catch (IllegalArgumentException illegalArgumentException)
>         {
>             value = null;
>         }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to