简体   繁体   English

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

[英]JSF 2 Composite Component EL type conversion error

I have a JSF Composite Component that has a EL Expression on the Interface part, code snippet below.我有一个 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>

Now my problem is that the "default="#{cc.attrs.label ne null}" is giving an error.现在我的问题是 "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

I'm using JSF 2.0.4, EL 2.1, WAS 7我正在使用 JSF 2.0.4、EL 2.1、WAS 7

The #{cc.attrs} is only available inside <cc:implementation> . #{cc.attrs}仅在<cc:implementation>中可用。

I'd suggest to rewrite it as follows:我建议将其重写如下:

<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