如何检查复合组件中是否存在可选属性

MyF*_*ist 11 attributes composite-component jsf-2

我需要验证我的复合组件中是否已传递可选属性.我怎样才能做到这一点?

<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>
Run Code Online (Sandbox Code Playgroud)

default属性设置为xxxfor <composite:attribute>不是我正在寻找的.

Bal*_*usC 12

您可以检查是否#{not empty cc.attrs.attr2}评估为true.

例如rendered,在任意组件的属性内:

<composite:implementation>
    <h:panelGroup rendered="#{not empty cc.attrs.attr2}">
        Attribute attr2 is not empty!
    </h:panelGroup>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)