开发者

JSF h:column tag not evaluating rendered attribute

I've got a JSF data table that conditionally displays each item based on a Boolean property of the item, as follows:

<h:dataTable value='#{sessionBean.items}' var='item'>
    <h:column rendered='#{item.visible}'>
        <h:outputText value='#{item.description}'/>
    </h:column>
</h:dataTable>

My problem is that the rendered attribute does not seem to be referring to visible property in my item at all. I've put a tracing message in the getter for the property, and can confirm that the getter is not getting called at all. What really puzzles me though, is that the following works:

<h:dataTable value='#{sessionBean.items}' var='item'>
    <h:column rendered='true'>
        <h:outputText value='visible = #{item.visible}'/>
        <h:outputText value='#{item.description}'/>
    </h:column>
</h:dataTable>

That is, in this case all items are rendered, and the text "visible = true" or "visible = false" is s开发者_开发技巧uccessfully output for each. It is only in the column rendered attribute that the getter is not working.

Does anyone have any idea what might cause this behaviour, and what I should do to correct it?


Table columns (read: <td> elements which are all in the same column, which thus applies on all rows) cannot be rendered on a per-row basis. That's not really a JSF restriction, but more a HTML restriction. Ask yourself, how should the HTML end up to look like? What should the browser do with all those missing <td> elements on a per-row basis? Right, it makes no sense at all :)


Just move the row-based rendering to the cell contents:

<h:column>
    <h:outputText value="#{item.description}" rendered="#{item.visible}"/>
</h:column>

Or make it a bean based rendering if you actually want to hide the whole column altogether:

<h:column rendered="#{sessionBean.visible}">
    <h:outputText value="#{item.description}"/>
</h:column>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜