2

Does anybody know what h:dataTable bodyrows means? I tried a simple example, but I don't understand what it's supposed to do.

<h:dataTable bodyrows="d" value="#{index.publishDates}" var="d">

Is this some sort of shortcut for making a table? I don't see any rows because of the bodyrows annotation. If h:column does columns, what does bodyrows do?

I don't understand the documentation.

This must be a comma separated list of integers. Each entry in this list is the row index of the row before which a "tbody" element should be rendered.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
K.Nicholas
  • 10,956
  • 4
  • 46
  • 66
  • It is exactly what it says in the [documentation](https://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/h/dataTable.html). – user207421 Feb 25 '16 at 04:23
  • There is also "If the current row index is contained in the "bodyrows" attribute, check if a "tbody" start element was rendered that needs to be closed, and if so, close the "tbody" element. Then render a "tbody" element start. Otherwise, do not render a "tbody" element." If you've read all this why are you setting it to `"d"`? – user207421 Feb 25 '16 at 05:06
  • That doesn't explain it to me. Example anyone? – K.Nicholas Feb 25 '16 at 05:12
  • play with it and look at the generated HTML... EJP is complete right. This results,clientside, in multiple tbody tags in a table.. http://stackoverflow.com/questions/3076708/can-we-have-multiple-tbody-in-same-table. Understanding basic html and css is required when using jsf... – Kukeltje Feb 25 '16 at 07:52
  • Thank you all, I was able to sort out what it does. – K.Nicholas Feb 25 '16 at 15:31

1 Answers1

1

In HTML, a <table> can have multiple bodies via <tbody>.

<table>
    <tbody>...</tbody>
    <tbody>...</tbody>
    <tbody>...</tbody>
</table>

By default, a <h:datatable> generates only one body like below.

<h:dataTable value="#{[1,2,3,4,5]}" var="i">
    <h:column>#{i}</h:column>
</h:dataTable>

<table>
    <tbody>
        <tr><td>1</td></tr>
        <tr><td>2</td></tr>
        <tr><td>3</td></tr>
        <tr><td>4</td></tr>
        <tr><td>5</td></tr>
    </tbody>
</table>

The bodyrows attribute can be used to specify a commaseparated string of row indexes which should start as a new body.

<h:dataTable value="#{[1,2,3,4,5]}" var="i" bodyrows="0,2,4">
    <h:column>#{i}</h:column>
</h:dataTable>

<table>
    <tbody>
        <tr><td>1</td></tr>
        <tr><td>2</td></tr>
    </tbody>
    <tbody>
        <tr><td>3</td></tr>
        <tr><td>4</td></tr>
    </tbody>
    <tbody>
        <tr><td>5</td></tr>
    </tbody>
</table>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555