I need this HTML output:
<tr>
<th>...</th>
<td>...</td>
<td>...</td>
</tr>
<tr>
<th>...</th>
<td>...</td>
开发者_StackOverflow社区 <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?
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!
精彩评论