Enum values in Composite Component attribute

南楼画角 提交于 2019-12-12 11:20:09

问题


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:


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.



来源:https://stackoverflow.com/questions/7902547/enum-values-in-composite-component-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!