4

I have a JSF Composite Component that has a EL Expression on the Interface part, code snippet below.

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

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

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Jin
  • 77
  • 1
  • 6

1 Answers1

7

The #{cc.attrs} is only available inside <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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • And one more thing, I did try to run the code above on Glassfish 3 and it seem to be running perfectly, am I missing something? Config or a jar maybe? Thanks again. – Jin Jun 08 '11 at 02:18