是否可以将类添加到JSF复合组件的子级?

时间:2017-10-20 09:44:22

标签: css jsf jsf-2 composite-component

正如标题所说,我想根据指定的属性为复合组件的子元素添加一个类。

这是我的复合组件 ButtonBar.xhtml

<!-- INTERFACE -->
<composite:interface>
    <composite:attribute name="spacing" default="2"/>
    <composite:attribute name="disablePrimary" default="false"/>
</composite:interface>

<!-- IMPLEMENTATION -->
<composite:implementation>
    <div class="button-bar">
        <div class="col-sm-#{cc.attrs.spacing}">
        </div>
        <div class="col-sm-#{12 - cc.attrs.spacing}">
            <h:panelGroup>
                <composite:insertChildren/>
            </h:panelGroup>
        </div>
    </div>      
</composite:implementation>

用法看起来像 index.xhtml

<myCc:ButtonBar>
    <b:commandButton value="Save"   action="#{ctrl.save()}" />
    <b:commandButton value="Delete" action="#{ctrl.delete()}" />
    <b:commandButton value="Cancel" action="#{ctrl.cancel()}" />
</myCc:ButtonBar>

我的css已经有一个主要按钮类,可以突出显示它们。如果没有另外指定(通过disablePrimary attr),我想将该类添加到第一个孩子。

那么可以访问/编辑将插入复合组件的子项属性吗?

否则我想我会通过在按钮栏中添加另一个类并通过带.button-bar.firstIsPrimary button:first-child的css设置第一个按钮的样式来实现。 (其他想法是受欢迎的)即使这不是很好,因为我必须手动复制按钮可以拥有的所有状态的所有css规则(active hover visited等。)

0 个答案:

没有答案