JSF 2.0: <f:viewParam> and default converters

可紊 提交于 2019-12-10 10:13:18

问题


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:


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

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


来源:https://stackoverflow.com/questions/11628169/jsf-2-0-fviewparam-and-default-converters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!