Why does composite component "rendered" attribute throw an IllegalArgument Exception?
Asked Answered
M

1

7

I create a composite component like this:

<cc:interface>        
    <cc:attribute name="value" 
                  required="true" />
    <cc:attribute name="rendered"
                  displayName="True to render"
                  default="true" />
</cc:interface>

When I invoke this component, I get an IllegalArgumentException. I can changed the rendered name to something else (like doIt) and then it works.

Is the rendered attribute reserved somehow? I want my composite component to look like "regular" JSF components.

This is with Mojarra.

Muniment answered 12/11, 2011 at 17:59 Comment(2)
In the future, you don't need to explicitly tag [mojarra] if the problem is not Mojarra specific. You would have exactly the same problem when you tried for example MyFaces. Just mentioning JSF impl/version in the question is sufficient.Artwork
I put Mojarra there because I thought it might be a Mojarra bug. But point taken.Muniment
A
16

Composite components extend UINamingContainer which in turn extend UIComponentBase which in turn already definies the id and rendered attributes. You don't need to specify them yourself. Just remove the <cc:attribute name="rendered">. If you specify the rendered attribute on the composite component tag, then it'll be interpreted and applied on the composite component itself.

If you intend to render specific children of the composite, then better invent a different attribute name. For example, renderSomeChild.

Artwork answered 12/11, 2011 at 22:50 Comment(3)
When editing the component in the NetBeans 7.1 editor, it considers the rendered attribute to be an error when it is not defined by a cc:attribute element. Is that a Netbeans bug?Muniment
Sorry, I have not really used Netbeans for more than 5 minutes. It works fine that way in Eclipse.Artwork
As much sense as you answer makes, it have the same problem in Eclipse: The "rendered" attribute of my own composition component is underlined and marked as an unknown element. JSF 2.1.24, Eclipse 3.7.2 with JBOSS JSF tools.Ujiji

© 2022 - 2024 — McMap. All rights reserved.