Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check presence of optional attribute inside a composite component

I need to verify whether an optional attribute has been passed or not within my composite component. How can I achieve this?

<composite:interface>
    <composite:attribute name="attr1" />
    <composite:attribute name="attr2" required="false" /> <!-- means OPTIONAL -->
</composite:interface>
<composite:implementation>
    <!-- How I can verify here whether attr2 is present or not whenever this component is used? -->
</composite:implementation>

Setting the default attribute to xxx for <composite:attribute> is not what I'm looking for.

like image 854
MyFist Avatar asked Dec 04 '12 12:12

MyFist


1 Answers

You could just check if #{not empty cc.attrs.attr2} evaluates to true.

E.g. inside the rendered attribute of an arbitrary component:

<composite:implementation>
    <h:panelGroup rendered="#{not empty cc.attrs.attr2}">
        Attribute attr2 is not empty!
    </h:panelGroup>
</composite:implementation>
like image 172
BalusC Avatar answered Oct 22 '22 18:10

BalusC