How can I show / hide JSF data column using ajax?

I have an ajax call that updates the following table. Can I have a Grade column (this is BigDecimal) if all values ​​are zero, otherwise it should be displayed?

<h:dataTable id="theTable" value="#{MyBean.people}" var="person"> <h:column> <f:facet name="header"> <h:outputText value="Name" /> </f:facet> #{person.name} </h:column> <h:column rendered="#{person.score != null}"> <f:facet name="header"> <h:outputText value="The Score" /> </f:facet> #{person.score} </h:column> </h:dataTable> 

The current render always does a NOT render column, even if the points are not equal to zero.

+4
source share
1 answer

There is no β€œeasy” way to do this; you must look at the complete collection yourself. You can write a helper method that checks your list for null values:

 public boolean isAllScoresNull() { for(Person p : people) { if(p.getScore != null) return false; } return true; } 

and use this via EL on your page:

 ... <h:column rendered="#{myBeanController.allScoresNull}"> ... 

You can also define a TagFunction for this task.

+5
source

All Articles