【问题标题】:Check if a datatable is empty in primefaces检查primefaces中的数据表是否为空
【发布时间】:2017-11-15 10:38:36
【问题描述】:

我有一个带有 jsf 的 primefaces 数据表,我需要使用 jquery/js 检查数据表何时为空,但我刚刚找到了不适用于 PF 的“普通”数据表的标签。

豆子

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

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>	

【问题讨论】:

  • 如果您只想显示一条消息,只要数据表为空 - 不包含任何记录,则可以使用名为 emptyMessage 的属性。
  • 不,我需要它在表格为空时禁用导出命令按钮
  • 然后向 commandButton 添加一个 disabled 属性,该属性采用与 dataTable 的值相同的“列表”,但在此处添加一个空检查...
  • 它也没有用
  • 阅读stackoverflow.com/questions/8634156/…,看看'header' facet是一个命名容器,还是别的什么......

标签: javascript jquery jsf primefaces datatable


【解决方案1】:

您的p:dataTable 很可能引用了一个列表。为它添加一个 ajax 事件处理程序,例如过滤器(所有可以使页面为空的过滤器)

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

使用带有disabled 属性的p:commandButton,如下所示:

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

如果列表为空,它会禁用 commandButton 客户端服务器端。所以用户也不能在客户端破解它。

commandButton 中的 'update' 元素确保按钮状态是,嗯,......更新相关事件。这些都是相当基本的 ajax 东西,也许可以阅读一些关于它的教程

【讨论】:

  • 我已经尝试过了,但是当我手动更新页面时按钮被禁用
  • 那么你需要数据表中的 ajax 事件,主要是在过滤器上,在这里你“更新”命令按钮
  • 我尝试过使用 ajax 事件监听,但效果相同
  • 那么你有一个不同的问题......这对我来说在我使用它的所有情况下都适用
  • 阅读这个:stackoverflow.com/questions/8634156/… 它可能会有所帮助
猜你喜欢
  • 2012-11-25
  • 2017-02-20
  • 1970-01-01
  • 1970-01-01
  • 2021-03-08
  • 2014-04-15
  • 1970-01-01
  • 2012-02-28
相关资源
最近更新 更多