JSF 2 : dataTable columnClasses is not replicated after 2 columns

烈酒焚心 提交于 2020-01-02 06:11:09

问题


Im using glassfish 3.0.1 and was experimenting with columnClasses in dataTable for the first time.

It's something like this :

<h:dataTable value="#{coreGridBean.heroBeanList}" var="hero"
                    captionStyle="font-size: 0.95em; font-style:italic"
                    styleClass="orders"
                    headerClass="ordersHeader"
                    footerClass="ordersHeader"
                    columnClasses="oddColumn,evenColumn">

From the core jsf book im reading, it says that by specifying only 2 classes in the columnClasses attribute, those 2 will be repeated when the column amount is more than 2.

Let's say that i have five columns, the columnClasses would become something like oddColumn,evenColumn,oddColumn,evenColumn,oddColumn, and we just need to define it like this : columnClasses="oddColumn,evenColumn"

But in my experience with 3 columns, it's not like this. From the third column they got no classes. I had to specify columnClasses="oddColumn,evenColumn,oddColumn" to make it work

Is this a bug or i just have a bad error ?


回答1:


The repetition only applies on rowClasses.

From the JSF 2.0 h:dataTable tag documentation:

columnClasses

Comma-delimited list of CSS style classes that will be applied to the columns of this table. A space separated list of classes may also be specified for any individual column. If the number of elements in this list is less than the number of actual column children of the UIData, no "class" attribute is output for each column greater than the number of elements in the list. If the number of elements in the list is greater than the number of actual column children of the UIData, the elements at the posisiton in the list after the last column are ignored.


rowClasses

Comma-delimited list of CSS style classes that will be applied to the rows of this table. A space separated list of classes may also be specified for any individual row. Thes styles are applied, in turn, to each row in the table. For example, if the list has two elements, the first style class in the list is applied to the first row, the second to the second row, the first to the third row, the second to the fourth row, etc. In other words, we keep iterating through the list until we reach the end, and then we start at the beginning again.

Maybe the book was wrong, or you misread the book.

Since the column number is usually always fixed in the view definition anyway, it's little effort to just repeat them yourself.

<h:dataTable columnClasses="oddColumn,evenColumn,oddColumn,evenColumn">
    <h:column></h:column>
    <h:column></h:column>
    <h:column></h:column>
    <h:column></h:column>
</h:dataTable>


来源:https://stackoverflow.com/questions/4627377/jsf-2-datatable-columnclasses-is-not-replicated-after-2-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!