繁体   English   中英

JSF 2 复合元件EL类型转换错误

[英]JSF 2 Composite Component EL type conversion error

我有一个 JSF 复合组件,它在接口部分有一个 EL 表达式,代码片段如下。

<cc:interface>
     <cc:attribute name="label" type="java.lang.String"/>
     <cc:attribute name="labelRendered" default="#{cc.attrs.label ne null}"/>
</cc:interface>
<cc:implementation>
     <h:outputText rendered="#{cc.attrs.labelRendered}" value="#{cc.attrs.label}"/>
</cc:implementation>

现在我的问题是 "default="#{cc.attrs.label ne null}" 给出了一个错误。

java.lang.IllegalArgumentException: Cannot convert /resources/cc/label.xhtml @20,85 default="#{cc.attrs.label != null}" of type class com.sun.faces.facelets.el.TagValueExpression to class java.lang.Boolean

我正在使用 JSF 2.0.4、EL 2.1、WAS 7

#{cc.attrs}仅在<cc:implementation>中可用。

我建议将其重写如下:

<cc:interface>
    <cc:attribute name="label" type="java.lang.String"/>
    <cc:attribute name="labelRendered" type="java.lang.Boolean" />
</cc:interface>
<cc:implementation>
    <ui:param name="labelRendered" value="#{empty cc.attrs.labelRendered ? not empty cc.attrs.label : cc.attrs.labelRendered}" />
    ...
    <h:outputText rendered="#{labelRendered}" value="#{cc.attrs.label}"/>
</cc:implementation>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM