编程语言
首页 > 编程语言> > Java-JSF 2.0:和默认转换器

Java-JSF 2.0:和默认转换器

作者:互联网

我想为视图参数使用标准的JSF转换器(javax.faces.convert.DateTimeConverter)

从文档中:

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

然后,我尝试:

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

但我明白了

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

然后,我尝试了第二个选项(按ID).我在faces-config.xml中定义了转换器

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

并使用了ID

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

在这种情况下

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

有没有办法让JSF实例化转换器,或者我必须手动实例化它(在某些bean中)?

解决方法:

转换器ID为javax.faces.DateTime,因此请尝试

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

标签:jsf,converter,jsf-2,datetime,java
来源: https://codeday.me/bug/20191101/1980712.html