2012-11-16 29 views
1

根据与stackoverflow下面列出的问题中所述相同的问题,在受管Bean中有Converter的实例后,我得到一个异常,该对象是未找到。表达式错误:命名对象:[email protected]找不到

Expression Error: Named Object: [email protected] not found 

#1问题:

我的XHTML代码:

<h:selectManyCheckbox value="#{bean.selectedEmployees}"> 
    <f:converter converterId="#{bean.entityConverter}" /> 
    <f:selectItems value="#{bean.allEmployees}" var="e" itemLabel="#{e.name}" />  
</h:selectManyCheckbox> 

回答

1

converterId属性需要转换器ID(转换器名称)。任何EL表达式值都被评估为String。你基本上将toString()转换器实例的结果传递给它,即[email protected]。该转换器ID反过来不被识别为任何已注册的转换器。然而..你不想传递转换器ID,而只是引用整个转换器实例。

converterId属性是错误的属性,只要您想引用整个具体实例。改为使用binding属性,或使用输入组件的converter属性。

因此,这样

<h:selectManyCheckbox value="#{bean.selectedEmployees}"> 
    <f:converter binding="#{bean.entityConverter}" /> 
    <f:selectItems value="#{bean.allEmployees}" var="e" itemLabel="#{e.name}" />  
</h:selectManyCheckbox> 

<h:selectManyCheckbox value="#{bean.selectedEmployees}" converter="#{bean.entityConverter}"> 
    <f:selectItems value="#{bean.allEmployees}" var="e" itemLabel="#{e.name}" />  
</h:selectManyCheckbox> 
+0

谢谢,解决了我的问题! –

+0

不客气。 – BalusC

-2

它缺少converter名称。你的名字可能像entityConverter。默认将是calss名称。使用如下;

<f:converter converterId="#{entityConverter}" /> 
+0

我不使用'面孔,config.xml'命名的转换器。我在托管bean中引用了一个转换器实例。查看链接的stackoverflow问题。不过,谢谢你的回答。 ;) –

+0

即使你使用注解,转换器也有一个名称。 – CycDemo

+0

你在这里通过所有的转换器本身作为它的ID。我不认为这是正确的。 –

相关问题