有条件地使用JSF Datatable显示行 [英] Conditionally display row using JSF Datatable
问题描述
任何建议?
< h:dataTable styleClass = resultTableid =t1value =#{r.common}var =comheaderClass =headerBackgrndrowClasses =rowOdd,rowEvencolumnClasses =leftAlign,rightAlign,leftAlign>
< h:column>
< h:outputText rendered =#{com.rendered}styleClass =inputTextvalue =#{com.description}:/>
< / h:column>
< h:column>
< h:outputText styleClass =outputTextvalue =#{com.v1}/>
< / h:column>
< h:column>
< h:inputText styleClass =inputTextvalue =#{com.v2}/>
< / h:column>
< / h:dataTable>
基本上说,#{com.rendered}
将有条件地显示单个单元格的内容,当 com.rendered
为false时,会生成一个空单元格。但是我想在某些条件下跳过整行显示,我该怎么做?
行对应到您的表的集合中的数据对象。如果你不想要这行,不要将对象放在集合中。
或者,你可以使用 rowClasses
dataTable参数。
Bean代码:
public String getRowClasses(){
StringBuilder sb = new StringBuilder();
for(数据数据:myData){
sb.append(data.hide?'hide,':'show,');
}
return sb.toString();
}
CSS:
tr.hide {display:none;}
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;}
这篇关于有条件地使用JSF Datatable显示行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!