creating tables in faces

hi

I need to create tabel like this one in html:

<table>

<!-- first row of header -->

<tr class="header">

<td></td>

<td colspan="2"></td>

<td colspan="2"></td>

</tr>

<!-- second row of header -->

<tr class="header">

<td></td>

<td ></td>

<td ></td>

<td ></td>

<td ></td>

</tr>

<!-- rows od data -->

<td></td>

<td ></td>

<td ></td>

<td ></td>

<td ></td>

</tr>

</table>

I have managedBean myBean with Collection col including data for table

How can I do it using Faces?

[845 byte] By [feel82a] at [2007-10-2 21:04:56]
# 1

Normally you would use h:panelGrid for this. However, there is no way in JSF to specify a colspan or rowspan. A nasty omission if you ask me, but that's the facts.

You can always wrap standard HTML tags in f:verbatim tags to make this work. It's what I ended up doing when I ran into the colspan/rowspan problem.

I've been speaking about the SUN JSF RI. There may be another release of JSF out there that contains a component that will allow you to do colspans. Check out MyFaces; maybe it has a component. Probably somebody else on the forums will be able to point you towards another JSF RI (if another exists).

Hope this helps,

CowKing

IamCowKinga at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Could you give me an example how to wrap standard HTML tags in f:verbatim tags to make this work in this case?
feel82a at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Wrapping an HTML tag in f:verbatim...

<f:verbatim><TABLE border="0" cellpadding="1" blah blah></f:verbatim>

Do not put any JSF tags inside the f:verbatim tags. i.e. DON'T do this:

<f:verbatim><TD><h:outputText value="#{bean.whatever}" /></TD></f:verbatim>

If you include a JSF tag you must close the f:verbatim first, then write the JSF. So the above example should be:

<f:verbatim><TD></f:verbatim>

<h:outputText value="#{bean.whatever}" />

<f:verbatim></TD></f:verbatim>

CowKing

IamCowKinga at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
You can use this library instead of doing all that work of wrapping tags: http://www.jsftutorials.net/htmLib/
pringia at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

OK. Let say I want to use htmlLib (prefix "htm"). I tried to combine htmlLib-Tags with faces h:datatable tag, like this:

<h:dataTable id="myTable" value="#{myBean.myColl}" var="item">

<htm:tr>

<htm:td>firstHeader1</htm:td>

<htm:td colspan="2">firstHeader2</htm:td>

<htm:td colspan="2">firstHeader3</htm:td>

</htm:tr>

<h:column >

<f:facet name="header" >

<h:outputText value="secondHeader1"/>

</f:facet>

<h:outputText value="#{item.filed1}" />

</h:column>

<h:column >

<f:facet name="header" >

<h:outputText value="secondHeader2"/>

</f:facet>

<h:outputText value="#{item.filed2}" />

</h:column>

<h:column >

<f:facet name="header" >

<h:outputText value="secondHeader3"/>

</f:facet>

<h:outputText value="#{item.filed3}" />

</h:column>

<h:column >

<f:facet name="header" >

<h:outputText value="secondHeader4"/>

</f:facet>

<h:outputText value="#{item.filed4}" />

</h:column>

<h:column >

<f:facet name="header" >

<h:outputText value="secondHeader5"/>

</f:facet>

<h:outputText value="#{item.filed5}" />

</h:column>

Htm:tr part should display the first row of header. But it doesn't...

I can see correct table but without the first header. What am I doing wrong?

feel82a at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Put a facet named header
pringia at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
I have already one facet named "header". Should I use another one? I want the table to be like this one from the first post( with 2 rows of headers, one of them with colspans)
feel82a at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
you have a header to the column. You can also have a header to the table.
pringia at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

Something like this:

<h:dataTable id="myTable" value="#{myBean.myColl}" var="item">

<f:facet name="header">

<htm:tr>

<htm:td>firstHeader1</htm:td>

<htm:td colspan="2">firstHeader2</htm:td>

<htm:td colspan="2">firstHeader3</htm:td>

</htm:tr>

</f:facet>

......

pringia at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
thx. that's works quite well - rendered html code is not correct but i can live with that ;)
feel82a at 2007-7-13 23:50:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...