You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Janap <ja...@gmail.com> on 2008/08/20 14:16:24 UTC

Myfaces inputCalendar user defined data type


Hello all , 

As stated in the Myfaces documentation I want to use a user-defined DataType
to get and set values for the t:inputCalendar component.

Can someone help me to start off writing a converter..do I have to extend
java.faces...DateTimeConverter?


-- 
View this message in context: http://www.nabble.com/Myfaces-inputCalendar-user-defined-data-type-tp19068174p19068174.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Myfaces inputCalendar user defined data type

Posted by Janap <ja...@gmail.com>.
Hello  again,

I wrote a custom date converter which looks like below :

public class DateConvert extends DateTimeConverter {
    public Object getAsObject(FacesContext facesContext, UIComponent
uiComponent, String value)
    {
         java.util.Date date =
(java.util.Date)super.getAsObject(facesContext,uiComponent, value);
         String inputdate =  DateUtils.format(date);
         return (null == inputdate) ? ""  : inputdate;
    }
    
    public String getAsString(FacesContext context,UIComponent component,
Object value) {
        MyCustomDatetype mcdt =  (MyCustomDatetype)value;
        String s = mcdt.converttoString();
        return (null == s) ? "" : s;
    }
}

and I use this converter with my t:inputCalendar component. This works as
long as I work with java.util.Date objects. But when I want to use my custom
Date object, I do not get the value from the getter(getDateValue) into the
getAsString method , the param value always returns null.

I check the getter which is returning a proper object.

The getasObject works fine and I am able to convert user entered values to
my own date objects and then pass it on the the setDateValue method.


Code in JSp


   <t:inputCalendar id="detail"
            javascriptLocation="/common/myFacesCalendarScripts"
            imageLocation="/common/myFacesCalendarScripts"
            styleLocation="/common/myFacesCalendarScripts"
            converter="DateTimeConverter"
            styleClass="datebox" 
            maxlength="10" 
            value="#{Table.dateValue}" 
            renderAsPopup="true"
            renderPopupButtonAsImage="true"
            popupTodayString="#{LabelBean.LABEL_Today_is}"
            popupDateFormat="#{facesUtilBean.dateFormat}"
            helpText="" />


Code in mytable is pretty simple

public class Table {
 public void  setDateValue(MyCustomDatetype mcsd) {
 this.mcsd = mcsd;
}

 public MyCustomDatetype getDateValue() {
   return value;
}
}



Thank you for the help,

Janap

    


Janap wrote:
> 
> 
> Hello all , 
> 
> As stated in the Myfaces documentation I want to use a user-defined
> DataType to get and set values for the t:inputCalendar component.
> 
> Can someone help me to start off writing a converter..do I have to extend
> java.faces...DateTimeConverter?
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Myfaces-inputCalendar-user-defined-data-type-tp19068174p19070009.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.