You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Steven Gollery <sg...@cadrc.calpoly.edu> on 2007/05/30 20:28:16 UTC

t:inputDate and custom converters

I'm having problems getting t:inputDate to use a custom converter class. In
the page, I have this:

<t:inputDate id="dateOfBirth" type="date" popupCalendar="true" 
                  value="#{editPatient.dateOfBirth}" 
                  binding="#{editPatient.dobInput}"> 
    <f:converter converterId="dobConverter"/>
    <f:validator validatorId="dobValidator"/>
</t:inputDate>

And in faces-config.xml:

  <validator>
  	<validator-id>dobValidator</validator-id>
  
<validator-class>com.cdmtech.proj.LHSWebSite.jsf.backingBeans.DOBValidator</validator-class>
  </validator>
  
  <converter>
     <converter-id>dobConverter</converter-id>
    
<converter-class>com.cdmtech.proj.LHSWebSite.jsf.backingBeans.DOBConverter</converter-class>
  </converter>


If the values entered by the user can be converted to a date,
DOBValidator.validate gets called, as expected. But neither of the Converter
methods in DOBConverter ever get called.

I've used custom converters before without this problem. Anybody know what
I'm doing wrong here?

Steven Gollery

-- 
View this message in context: http://www.nabble.com/t%3AinputDate-and-custom-converters-tf3842118.html#a10879754
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: t:inputDate and custom converters

Posted by Mike Kienenberger <mk...@gmail.com>.
I'd call it a bug.

Steven, at minimum, it's probably worth opening a JIRA issue on this.
 Ideally you'd submit a patch to allow a converter to be specified.

On 5/30/07, Andrew Robinson <an...@gmail.com> wrote:
> Just looked at the code, the tomahawk input date renderer does not use
> the converter from the component in the 1.1.5 source. From
> HtmlDateRenderer:
>
>     public Object getConvertedValue(FacesContext context, UIComponent
> uiComponent, Object submittedValue) throws ConverterException {
>         UserData userData = (UserData) submittedValue;
>         try {
>             return userData.parse();
>         } catch (ParseException e) {
>             Object[] args = {uiComponent.getId()};
>             throw new
> ConverterException(MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,
> DATE_MESSAGE_ID, args));
>         }
>     }
>
> Either a bug or a short-coming. I would recommend reporting a new
> issue or feature request and then sub-classing the renderer yourself
> to add support. The one trick to this is that the submitted value is
> not a string as with other UIInput components that I have seen, so it
> doesn't look as simplistic to override. You will have to work with
> UserData and either sub-class it or update its values in the
> converter.
>
> On 5/30/07, Steven Gollery <sg...@cadrc.calpoly.edu> wrote:
> >
> > I'm having problems getting t:inputDate to use a custom converter class. In
> > the page, I have this:
> >
> > <t:inputDate id="dateOfBirth" type="date" popupCalendar="true"
> >                   value="#{editPatient.dateOfBirth}"
> >                   binding="#{editPatient.dobInput}">
> >     <f:converter converterId="dobConverter"/>
> >     <f:validator validatorId="dobValidator"/>
> > </t:inputDate>
> >
> > And in faces-config.xml:
> >
> >   <validator>
> >         <validator-id>dobValidator</validator-id>
> >
> > <validator-class>com.cdmtech.proj.LHSWebSite.jsf.backingBeans.DOBValidator</validator-class>
> >   </validator>
> >
> >   <converter>
> >      <converter-id>dobConverter</converter-id>
> >
> > <converter-class>com.cdmtech.proj.LHSWebSite.jsf.backingBeans.DOBConverter</converter-class>
> >   </converter>
> >
> >
> > If the values entered by the user can be converted to a date,
> > DOBValidator.validate gets called, as expected. But neither of the Converter
> > methods in DOBConverter ever get called.
> >
> > I've used custom converters before without this problem. Anybody know what
> > I'm doing wrong here?
> >
> > Steven Gollery
> >
> > --
> > View this message in context: http://www.nabble.com/t%3AinputDate-and-custom-converters-tf3842118.html#a10879754
> > Sent from the MyFaces - Users mailing list archive at Nabble.com.
> >
> >
>

Re: t:inputDate and custom converters

Posted by Andrew Robinson <an...@gmail.com>.
Just looked at the code, the tomahawk input date renderer does not use
the converter from the component in the 1.1.5 source. From
HtmlDateRenderer:

    public Object getConvertedValue(FacesContext context, UIComponent
uiComponent, Object submittedValue) throws ConverterException {
        UserData userData = (UserData) submittedValue;
        try {
            return userData.parse();
        } catch (ParseException e) {
            Object[] args = {uiComponent.getId()};
            throw new
ConverterException(MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,
DATE_MESSAGE_ID, args));
        }
    }

Either a bug or a short-coming. I would recommend reporting a new
issue or feature request and then sub-classing the renderer yourself
to add support. The one trick to this is that the submitted value is
not a string as with other UIInput components that I have seen, so it
doesn't look as simplistic to override. You will have to work with
UserData and either sub-class it or update its values in the
converter.

On 5/30/07, Steven Gollery <sg...@cadrc.calpoly.edu> wrote:
>
> I'm having problems getting t:inputDate to use a custom converter class. In
> the page, I have this:
>
> <t:inputDate id="dateOfBirth" type="date" popupCalendar="true"
>                   value="#{editPatient.dateOfBirth}"
>                   binding="#{editPatient.dobInput}">
>     <f:converter converterId="dobConverter"/>
>     <f:validator validatorId="dobValidator"/>
> </t:inputDate>
>
> And in faces-config.xml:
>
>   <validator>
>         <validator-id>dobValidator</validator-id>
>
> <validator-class>com.cdmtech.proj.LHSWebSite.jsf.backingBeans.DOBValidator</validator-class>
>   </validator>
>
>   <converter>
>      <converter-id>dobConverter</converter-id>
>
> <converter-class>com.cdmtech.proj.LHSWebSite.jsf.backingBeans.DOBConverter</converter-class>
>   </converter>
>
>
> If the values entered by the user can be converted to a date,
> DOBValidator.validate gets called, as expected. But neither of the Converter
> methods in DOBConverter ever get called.
>
> I've used custom converters before without this problem. Anybody know what
> I'm doing wrong here?
>
> Steven Gollery
>
> --
> View this message in context: http://www.nabble.com/t%3AinputDate-and-custom-converters-tf3842118.html#a10879754
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>

Re: t:inputDate and custom converters

Posted by Mike Kienenberger <mk...@gmail.com>.
I would check the code for inputDate's renderer.   I haven't used it,
but I know that inputCalendar internally sets its own
dateTimeConverter.

On 5/30/07, Steven Gollery <sg...@cadrc.calpoly.edu> wrote:
>
> I'm having problems getting t:inputDate to use a custom converter class. In
> the page, I have this:
>
> <t:inputDate id="dateOfBirth" type="date" popupCalendar="true"
>                   value="#{editPatient.dateOfBirth}"
>                   binding="#{editPatient.dobInput}">
>     <f:converter converterId="dobConverter"/>
>     <f:validator validatorId="dobValidator"/>
> </t:inputDate>
>
> And in faces-config.xml:
>
>   <validator>
>         <validator-id>dobValidator</validator-id>
>
> <validator-class>com.cdmtech.proj.LHSWebSite.jsf.backingBeans.DOBValidator</validator-class>
>   </validator>
>
>   <converter>
>      <converter-id>dobConverter</converter-id>
>
> <converter-class>com.cdmtech.proj.LHSWebSite.jsf.backingBeans.DOBConverter</converter-class>
>   </converter>
>
>
> If the values entered by the user can be converted to a date,
> DOBValidator.validate gets called, as expected. But neither of the Converter
> methods in DOBConverter ever get called.
>
> I've used custom converters before without this problem. Anybody know what
> I'm doing wrong here?
>
> Steven Gollery
>
> --
> View this message in context: http://www.nabble.com/t%3AinputDate-and-custom-converters-tf3842118.html#a10879754
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>