0

I need this HTML output:

<tr>
    <th>...</th>
    <td>...</td>
    <td>...</td>
</tr>
<tr>
    <th>...</th>
    <td>...</td>
    <td>...</td>
</tr>
etc...

I don't do JSF much and here's the JSF I'm working with:

<h:dataTable>
    <h:column>...</h:column>
    <h:column>...</h:column>
    <h:column>...</h:column>
</h:dataTable>

That, alas, doesn't give me any THs just 3 TDs. So I then tried this:

<h:dataTable>
    <h:column><f:facet name="header">...</f:facet></h:column>
    <h:column>...</h:column>
    <h:column>...</h:column>
</h:dataTable>

But that only gives me a TH in the first row, not every subsequent row.

Is there a way to do with with JSF without having to write some custom component of some sorts?

1 Answer 1

2

How important is it to have an actual TH in each row? If this is just for styling purposes you might be able to accomplish what you want with h:dataTable's "columnClasses" to give the first column a different CSS class.

<h:dataTable columnClasses="firstColumn">
   ... h:columns ...
</h:dataTable>

If you absolutely must have a TH element in each row, I can't think of a way to do this with h:dataTable, but you could use <ui:repeat> instead. This will work like old-school <c:forEach> where you render the <table>/<tr> yourself. For example:

<ui:repeat value="#{bean.list}" var="row">
  <tr>
    <th><h:outputText value="#{row.foo}"/></th>
    <td><h:outputText value="#{row.bar}"/></td>
  </tr>
</ui:repeat>

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.