【问题标题】:JSF 2 Composite Component EL type conversion errorJSF 2 复合组件 EL 类型转换错误
【发布时间】:2011-09-09 18:07:32
【问题描述】:

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

<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

【问题讨论】:

    标签: jsf el composite-component


    【解决方案1】:

    #{cc.attrs} 仅在 &lt;cc:implementation&gt; 内部可用。

    我建议改写如下:

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

    【讨论】:

    • 我会试试你的建议。非常感谢,:)
    • 还有一件事,我确实尝试在 Glassfish 3 上运行上面的代码,它似乎运行完美,我错过了什么吗?可能是配置还是罐子?再次感谢。
    猜你喜欢
    • 2014-03-07
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    • 2013-10-19
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    相关资源
    最近更新 更多