webtier@glassfish.java.net

Re: [webtier] Conditionally rendering h:column

From: Alex Sherwin <alex.sherwin_at_acadiasoft.com>
Date: Thu, 12 Nov 2009 14:53:03 -0500

You have to think of it in terms of how an HTML table is drawn, you
cannot have a variable number of columns per row. If you have a dataset
of 5 rows, and you're deciding the rendered attribute of h:column using
data from the row item where it is not rendered in one row only, you'll
be generating mal-formed HTML:

<table>
<tr><td>1</td><td>2</td</tr>
<tr><td>1</td><td>2</td</tr>
<tr><td>1</td><td>2</td</tr>
<tr><td>1</td><td>2</td</tr>
<tr><td>1</td>
</table>


Your condition for the rendered attribute of h:column can of course come
from anywhere, but it must be true for your entire dataset (and as such,
probably should not be derived from your iterated table data)

Uwe Seimet wrote:
> Hello,
>
> I have a question concerning the rendering of h:column. This JSP code
> fragment does not work for me as far as the rendered attribute of
> h:column is concerned:
>
> <h:dataTable value="#{bean.items}" var="item">
> <h:column rendered="{item.rendered}">
> <f:facet name="header">
> <h:outputText value="Header" />
> </f:facet>
> <h:outputText value="{item.rendered}" />
> </h:column>
> </h:dataTable>
>
> Even though the expression {item.rendered} returns the boolean value "true"
> the column is not rendered correctly. The actual column contents are
> displayed ("true") but the header is missing. It looks as if the column
> is in some kind of undefined state.
>
> My guess is that I cannot refer to the model data of the current row
> (i.e. #{item}) from within the 'rendered' attribute of h:column.
> Can anybody confirm this or is there something else I have to consider?
>
> Best regards
>
> Uwe
>
>