Enum values ​​in the Composite Component attribute

My problem is pretty simple: I want to create a composite component with the String, Type attribute.

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

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

+4
source share
1 answer

Unfortunately, no, you cannot put a compilation / build time limit on the attribute value of a composite component in the cc interface. However, you can limit the runtime 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 body here.</p> </ui:fragment> 

This will be your best choice.

+5
source

All Articles