简体   繁体   English

检查数据表的素数是否为空

[英]Check if a datatable is empty in primefaces

I have a datatable in primefaces with jsf and I need to check when the datatable is empty with jquery/js, but I have just found tags for "normal" datatables that don't work on PF. 我在jsf中的素面中有一个数据表,我需要用jquery / js检查该数据表何时为空,但我刚刚发现了在PF上不起作用的“普通”数据表的标记。

Bean 豆角,扁豆

private ArrayList<Curso> curs = null;
private ArrayList<Curso> listado_filtrado;
private DefaultStreamedContent informe_cursos;

Html HTML

 <p:outputPanel id="opTabla" > <p:dataTable id="tabla_elements" value="#{Cursos.curs}" var="element" filteredValue="#{Cursos.listado_filtrado}" emptyMessage="No se encontraron elementos" paginator="true" rows="20" currentPageReportTemplate="{startRecord} a {endRecord} de {totalRecords}" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" paginatorPosition="bottom"> <p:ajax event="filter" update="exportar"/> <f:facet name="header"> <div class="header-field-col"> <p:commandButton id="anadir_curso" value="Añadir curso nuevo" icon="ui-icon-plus" /> </div> <div class="header-field-col"> <p:commandButton id="exportar" value="Exportar" ajax="false" disabled="#{empty Cursos.curs}" icon="ui-icon-arrowreturnthick-1-s"> <p:fileDownload value="#{Cursos.informeCursos}" /> </p:commandButton> </div> </f:facet> 

Your p:dataTable most likely references a list. 您的p:dataTable最有可能引用一个列表。 Add an ajax event handler to it for eg the filter (all the ones that can make a page empty) 向其添加ajax事件处理程序,例如过滤器(所有可以使页面为空的过滤器)

<p:dataTable value="#{myBean.myList}"...>
    <p:ajax event="filter" update="exportButton" ... >
    ...
</p:dataTable>

use a p:commandButton with a disabled attribute like this: 使用具有disabled属性的p:commandButton ,如下所示:

<p:commandButton id="exportButton" value="export" disabled="#{empty myBean.myList}" ... />

It disables the commandButton client and serverside if the list is empty. 如果列表为空,它将禁用commandButton客户端服务器端。 So users cannot hack it client-side either. 因此,用户也无法在客户端进行黑客入侵。

The 'update' element in the commandButton makes sure the button state is, well,... updated on the relevant events. commandButton中的'update'元素可确保按钮状态在相关事件上已更新。 This is all rather basic ajax stuff, maybe read some tutorial on that 这些都是相当基本的ajax东西,也许阅读一些有关它的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM