Search code examples
javajsfdatetimejsf-2converters

JSF 2.0: <f:viewParam> and default converters


I would like to use a standard JSF converter (javax.faces.convert.DateTimeConverter) for a view parameter

From the documentation:

You can refer to the converter by class or by its ID using the component tag's converter attribute. The ID is defined in the application configuration resource file

I then tried:

<f:viewParam
    name        = "rangeStartCreationDate"
    value       = "#{doiListController.model.rangeStartCreationDate}"
    converter   = "javax.faces.convert.DateTimeConverter"
/>

but I get

javax.faces.FacesException: Expression Error: Named Object: javax.faces.convert.DateTimeConverter not found.

I then tried the second option (by ID). I defined the converter in faces-config.xml

<converter> 
    <converter-id>DateTimeConverter</converter-id> 
    <converter-class>javax.faces.convert.DateTimeConverter</converter-class> 
</converter>

and used the ID

<f:viewParam
    name        = "rangeStartCreationDate"
    value       = "#{doiListController.model.rangeStartCreationDate}"
    converterId = "DateTimeConverter"
/>

In this case I get

Conversion Error setting value 'Tue Jul 24 00:00:00 CEST 2012' for 'null Converter'.

Is there a way to let JSF instantiate the converter or to I have to instantiate it manually (in some bean)?


Solution

  • The converter id is javax.faces.DateTime, so try

    <f:viewParam
      converter="javax.faces.DateTime"
    ... />