【问题标题】:styling the last record in a jsf datatable样式化 jsf 数据表中的最后一条记录
【发布时间】:2012-02-28 08:38:16
【问题描述】:

我遇到的情况是,我的数据多于返回给 dataTable 元素的单行所能容纳的数据。为了解决这个问题,我简单地将结果合并到一个单元格中。我正在寻找一种方法来确定我是否已经到达结果集中的最后一个对象,以便我可以删除用作分隔符的底部边框。最终我不知道我要处理多少个对象。

.most {
    background-color:cyan;
    border-bottom:medium solid black;
}
.last {
    border-bottom:none;
}

<h:dataTable id="myTable" value="#{flowData.selectedItem.profile}" var="profile" columnClasses="most, last">
<h:column>
    <h:inputText id="_last" value="#{profile.last}" />
    <h:inputText id="_first" value="#{profile.first}" />
    <h:inputText id="_middle" value="#{profile.middle}" />
    <h:inputText id="_city" value="#{profile.city}" />
    <h:inputText id="_state" value="#{profile.state}" />
</h:column>
</h:dataTable>

提前感谢您的任何意见。

【问题讨论】:

    标签: css jsf datatable


    【解决方案1】:

    这取决于您要支持的 IE 浏览器版本。

    如果您不关心 IE6/7 支持,那么您可以为此使用 CSS2 :last-child 伪类。

    table.yourTableClass tbody tr td {
        background-color: cyan;
        border-bottom: medium solid black;
    }
    table.yourTableClass tbody tr:last-child td {
        border-bottom: none;
    }
    

    <h:dataTable ... styleClass="yourTableClass">
    

    (是的,IE7 支持 CSS2 伪类对应 :first-child,但它确实支持 :last-child!)

    如果您关心 IE7,但不关心 IE6,那么您也可以反过来使用 border-top 而不是在 :first-child 上设置为 noneborder-bottom

    table.yourTableClass tbody tr td {
        background-color: cyan;
        border-top: medium solid black;
    }
    table.yourTableClass tbody tr:first-child td {
        border-top: none;
    }
    

    如果您也关心 IE6(现在是 discutable),那么您不能在托管 bean 中自行生成行类(不是列类!)字符串。

    <h:dataTable ... rowClasses="#{flowData.rowClasses}">
    

    public String getRowClasses() {
        StringBuilder builder = new StringBuilder();
        int size = selectedItem.getProfile().size(); // getProfiles() ?
    
        for (int i = 0; i < size; i++) {
            builder.append((i + 1 < size) ? "most," : "last");
        }
    
        return builder.toString();
    }
    

    还有这个 CSS

    tr.more td {
        background-color: cyan;
        border-bottom: medium solid black;
    }
    tr.last td {
        border-bottom: none;
    }
    

    【讨论】:

    • 感谢您对解决此问题的各种方法的出色描述。最后,我选择从 bean 生成 rowClasses。它就像一个魅力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多