简体   繁体   English

为什么在使用JSF中的h:dataTable显示动态数据时,特定于边界的属性似乎不适用于行?

[英]Why don't the border-specific attributes seems to work on rows while displaying dynamic data using h:dataTable in JSF?

Consider: 考虑:

             <h:dataTable value="#{orderBean.orderList}" var="o" 
                styleClass="order-table"
                headerClass="order-table-header"
                rowClasses="order-table-odd-row,order-table-even-row" >

                <h:column>
                    <!-- column header -->
                    <f:facet name="header">Order No</f:facet>
                    <!-- row record -->
                    #{o.orderNo}
                </h:column>
                <h:column>
                    <f:facet name="header">Product Name</f:facet>
                    #{o.productName}
                </h:column>

                <h:column>
                    <f:facet name="header">Price</f:facet>
                    #{o.price}
                </h:column>

                <h:column>
                    <f:facet name="header">Quantity</f:facet>
                    #{o.qty}
                </h:column>
            </h:dataTable>

the included css file: 包含的css文件:

.order-table{   
    border-collapse:separate;
    border: 20px solid red ;

}

.order-table-header{
    text-align:center;
    background:none repeat scroll 0 0 #E5E5E5;
    border:5px solid #BBBBBB; 
    padding:16px;
}

.order-table-odd-row{
    text-align:center;

    background:none repeat scroll 0 0 blue;
    /* border:1px solid #BBBBBB; */
    /* border-top:1px solid red; */
    outline: 5px solid black;
}

.order-table-even-row{
    text-align:center;
    background:none repeat scroll 0 0 orange;

    /* border-left:5px solid pink; */
}

The commented out lines(if uncommented) in css file doesn't seems to have effect, while the outline attribute does show it effects. css文件中注释掉的行(如果未注释)似乎没有效果,而outline属性确实显示了它的效果。 Why? 为什么? Since I am new to CSS, I am ofcouse missing something. 因为我是CSS的新手,所以我很遗憾。 So, how will apply borders to specfic rows? 那么,如何将边界应用于特定行?

数据表

This is caused by border-collapse: separate; 这是由border-collapse: separate;引起的border-collapse: separate; property on the parent table — which is by the way already the default value on most browsers. 父表上的属性 - 这在大多数浏览器中已经是默认值。

.order-table {
    border-collapse: separate;
    ...
}

This behavior is specified in CSS 2.1 spec chapter 17.6.1 "The separated borders model" , of which a relevant part is cited below (emphasis mine): 此行为在CSS 2.1规范 第17.6.1章“分离的边界模型”中指定 ,其中相关部​​分在下面引用(强调我的):

In this model, each cell has an individual border. 在此模型中,每个单元格都有一个单独的边框。 The 'border-spacing' property specifies the distance between the borders of adjoining cells. 'border-spacing'属性指定相邻单元格边框之间的距离。 In this space, the row, column, row group, and column group backgrounds are invisible, allowing the table background to show through. 在此空间中,行,列,行组和列组背景不可见,允许显示表背景。 Rows, columns, row groups, and column groups cannot have borders (ie, user agents must ignore the border properties for those elements). 行,列,行组和列组不能具有边框 (即,用户代理必须忽略这些元素的边框属性)。

In other words, <tr> , <col> , <tbody> and <colgroup> cannot have any border set. 换句话说, <tr><col><tbody><colgroup>不能设置任何border

It'll work if you set border-collapse: collapse; 如果你设置border-collapse: collapse;它会工作border-collapse: collapse; on the parent table so that instead the rules as per CSS 2.1 spec chapter 17.6.2 "The collapsed borders model" is followed. 在父表上,以便遵循CSS 2.1规范第17.6.2节“折叠边框模型”的规则。

.order-table {
    border-collapse: collapse;
    ...
}

This changes the behavior of the border on all table elements, which may need some tweaking first on existing stylesheets targeted at separated border model, but is after all much more flexible and intuitive. 这会改变所有表格元素上边框的行为,这可能需要先针对分离边框模型的现有样式表进行一些调整,但毕竟更加灵活和直观。

An alternative is to set the borders via <td> element instead. 另一种方法是通过<td>元素设置边框。

(Ab)using the outline isn't entirely right for the purpose. (Ab)使用outline并不完全适合此目的。 Besides, it confuses you as to setting width/height/margin/padding as the outline basically doesn't take up any space. 此外,它会使您对设置宽度/高度/边距/填充感到困惑,因为outline基本上不占用任何空间。 It's like an absolutely positioned border, which you'd have to compensate with extra margin or padding. 它就像一个绝对定位的边框,你必须补偿额外的边距或填充。


Unrelated to the concrete problem: do note that this issue is not specific to JSF. 具体问题无关 :请注意此问题并非特定于JSF。 In the context of this question, JSF is merely a HTML code generator. 在这个问题的上下文中,JSF只是一个HTML代码生成器。 You'd have had exactly the same problem when having a "plain vanilla" .html file with a hardcoded <table><tr><td> with some test data stubbed. 当有一个带有硬编码<table><tr><td>的“普通香草” .html文件时,你会遇到完全相同的问题,其中包含一些测试数据。 CSS experts would have answered this question easier if you have left JSF out of the context and instead presented a minimal plain HTML code snippet reproducing the problem (you can get started with the JSF-generated HTML source as you can find via rightclick, View Source in webbrowser). 如果你把JSF放在上下文之外,CSS专家会更容易回答这个问题,而是提供一个简单的HTML代码片段来重现这个问题(你可以通过右键单击查看源代码 ,开始使用JSF生成的HTML源代码, 查看源代码在webbrowser)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM