I have some JSF code that currently works (as shown below), and I need to modify it to conditionally suppress the display of certain rows of the table. I know how to conditionally suppress the display of a particular cell, but that seems to create an empty cell, while what I'm trying to do is to not display the row at all.
Any suggestions?
<h:dataTable styleClass="resultsTable" id="t1" value="#{r.common}" var="com" headerClass="headerBackgrnd" rowClasses="rowOdd, rowEven" columnClasses="leftAlign, rightAlign, leftAlign">
<h:column>
<h:outputText rendered="#{com.rendered}" styleClass="inputText" value="#{com.description}: " />
</h:column>
<h:column>
<h:outputText styleClass="outputText" value="#{com.v1}" />
</h:column>
<h:column>
<h:inputText styleClass="inputText" value="#{com.v2}" />
</h:column>
</h:dataTable>
Basically, the line that says #{com.rendered}
will conditionally display the contents of a single cell, producing an empty cell when com.rendered
is false. But I want to skip an entire row of the display under certain conditions - how would I go about doing that?
Rows correspond to data objects in the collection of your table. If you don't want the row, don't put the object in the collection.
Alternatively, you can use the rowClasses
parameter for dataTable.
Bean code:
public String getRowClasses() {
StringBuilder sb = new StringBuilder();
for (Data data : myData) {
sb.append(data.hide ? 'hide,' : 'show,');
}
return sb.toString();
}
CSS:
tr.hide {display:none;}
For people using richFaces, you can use rich:column's filterExpression attribute.
<rich:column filterExpression="#{put your expression here}">
...
</rich>
If the condition is not met, the complete row is filtered out.
Example is using seam EL!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With