JSF h: column tag does not evaluate rendered attribute

I have a JSF data table that conditionally displays each element based on the logical property of the element 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 doesn't seem to apply to the visible property in my element at all. I sent a trace message to getter for the property and I can confirm that getter is not called at all. However, what really puzzles me is this:

 <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 the elements are displayed, and for each result the text "visible = true" or "visible = false" is successfully displayed. It only in the rendered column attribute rendered not work.

Does anyone know what can cause this behavior, and what should I do to fix it?

+4
source share
1 answer

Table columns (read: <td> elements that are in the same column, which thus applies to all rows) cannot be displayed on each row. This is not just a JSF limitation, but a bigger HTML limitation. Ask yourself how HTML should look like this? What should the browser do with all missing <td> elements for each line? That's right, that doesn't make any sense :)


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

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

Or do a bean-based rendering if you really want to completely hide the entire column:

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

Source: https://habr.com/ru/post/1338040/


All Articles