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