【问题标题】:What is the best way to use composite components for columns of data table?将复合组件用于数据表列的最佳方法是什么?
【发布时间】:2015-03-18 08:23:59
【问题描述】:

我有两个内部带有<h:dataTable> 的复合组件,它们的不同之处仅在于几个<h:column> 的内容。 使用复合组件的可能性来逃避复制粘贴的最佳方法是什么?我知道标签,但我们的项目中没有任何标签。所以,这对我来说不是解决方案。

【问题讨论】:

    标签: jsf composite-component


    【解决方案1】:

    为你的复合组件添加一个属性:

    <cc:interface>
        <cc:attribute name="columnType" type="java.lang.String" required="true" />
    </cc:interface>
    

    然后在实现中

     <h:column rendered="#{cc.attrs.columnType eq 'typeAColumns'>
         #{data.valueForColumnTypeA}
     </h:column>
     <h:column rendered="#{cc.attrs.columnType eq 'typeBColumns'>
         #{data.valueForColumnTypeB}
     </h:column>
    

    你可以像这样使用它

     <my:compositeTable columnType="typeAColumns"/>
     <my:compositeTable columnType="typeBColumns"/>
    

    【讨论】:

    • 是的,但是我会在一个组件中混合一些实现。今天我只有两个实现,明天三个。然后怎样呢?我会得到巨大的组件,这将很难维护。不行。据我了解,没有最好的方法来使用复合组件来重用数据表。我必须使用标签或渲染属性或进行复制粘贴。在我看来,这是不好的方式。我希望将来我们能从 JSF Team 那里得到一些东西。
    猜你喜欢
    • 2010-12-22
    • 1970-01-01
    • 2010-09-16
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 2010-09-05
    • 2019-03-17
    • 2020-04-10
    相关资源
    最近更新 更多