JSF 2.0: and default converters

2019-05-11 22:00发布

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)?

1条回答
Animai°情兽
2楼-- · 2019-05-11 22:30

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

<f:viewParam
  converter="javax.faces.DateTime"
... />
查看更多
登录 后发表回答