复合组件属性中的枚举值

bob*_*mar 4 attributes composite-component jsf-2

我的问题很简单:我想创建一个带有String属性Type的复合组件.

<cc:attribute name="type" /> 该属性将有3个可接受的值,[TYPE1,TYPE2,TYPE3]

是否可以说我的组件只接受这些值?

Bal*_*usC 5

遗憾的是,您不能对cc接口中的复合组件属性值进行编译/构建时限制.但是,您可以通过检查cc实现中的值来设置运行时限制.

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

那将是你最好的选择.