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

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

我不是在寻找将default属性的xxx设置为<composite:attribute>的ojit_code。

最佳答案

您可以只检查#{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>

关于jsf-2 - 如何检查复合组件内部是否存在可选属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13702713/

10-10 09:00