设置 jsf 数据表中最后一条记录的样式

发布于 2025-01-02 20:11:21 字数 776 浏览 0 评论 0原文

我遇到的情况是,我的数据多于返回到 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>

预先感谢您的任何意见。

I have a situation where I have more data than can be accommodated in a single row being returned to a dataTable element. In order to deal with this I have simply combined the results into a single cell. What I am looking for is a way to determine whether or not I have reached the last object in the result set so that I can drop the bottom-border used as my separator. Ultimately I do not know how many objects I will be dealing with.

.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>

Thanks in advance for any input.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懵少女 2025-01-09 20:11:21

这取决于您想要支持的 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 而不是 border-bottom代码> 设置为none on :first-child

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

如果您也关心 IE6(即 现在是可讨论的),那么您就无法在托管 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;
}

That depends on the IE browser version which you'd like to support.

If you don't care about IE6/7 support, then you could use the CSS2 :last-child pseudoclass for this.

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

with

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

(yes, IE7 supports the CSS2 pseudoclass counterpart :first-child, but it does really not support the :last-child!)

If you care about IE7, but not about IE6, then you can also do it the other way round, with a border-top instead of border-bottom which is set to none on :first-child:

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

If you however also care about IE6 (which is discutable these days), then you can't go around generating the string of row classes (not column classes!) youself inside the managed bean.

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

with

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();
}

and this CSS

tr.more td {
    background-color: cyan;
    border-bottom: medium solid black;
}
tr.last td {
    border-bottom: none;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文