有条件地使用JSF Datatable显示行 [英] Conditionally display row using JSF Datatable

查看:120
本文介绍了有条件地使用JSF Datatable显示行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些目前可以工作的JSF代码(如下所示),我需要修改它以有条件地抑制表的某些行的显示。我知道如何有条件地抑制特定单元格的显示,但这似乎创建一个空单元格,而我正在尝试的是不显示行。



任何建议?

 < 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆