Enum values in Composite Component attribute

2019-06-27 16:12发布

My issue is quite simple : I want to create a composite component with a String attribute, Type.

<cc:attribute name="type" /> This attribute will have 3 acceptable values, [TYPE1, TYPE2, TYPE3]

Is it possible to say my component will accept only these values ?

1条回答
太酷不给撩
2楼-- · 2019-06-27 16:43

Unfortunately no, you cannot put a compile/buildtime restriction on a composite component attribute value in the cc interface. You can however put a runtime restriction by checking the value in the cc implementation.

<ui:param name="type" value="#{cc.attrs.type}" />
<ui:fragment rendered="#{type == 'TYPE1' or type == 'TYPE2' or type == 'TYPE3'}">
    <p>The type is TYPE1, TYPE2 or TYPE3.</p>
    <p>Write your component's body here.</p>
</ui:fragment>

That'll be your best bet.

查看更多
登录 后发表回答