2017-06-13 19 views
0

我在jsf的primefaces中有一個數據表,我需要檢查數據表何時爲jquery/js爲空,但是我剛剛找到了不能工作的「普通」數據表的標籤在PF上。檢查數據表是否在primefaces中爲空

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

的Html

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

+0

如果你只想顯示一條消息,只要數據表爲空 - 不包含任何記錄,則可以使用名爲emptyMessage的屬性。 – Tiny

+0

不,我需要它禁用導出命令按鈕,當表爲空 –

+0

然後添加一個禁用的屬性的命令按鈕,使用與dataTable的值中使用相同的'列表',但在那裏添加一個空的檢查... – Kukeltje

回答

2

p:dataTable最有可能引用列表。爲它添加一個ajax事件處理程序過濾器(可以使頁空所有的)

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

使用p:commandButtondisabled屬性是這樣的:

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

它禁用命令按鈕客戶服務器端如果列表空。所以用戶不能破解它的客戶端。

commandButton中的'update'元素確保按鈕狀態在相關事件上更新。這是所有相當基本的Ajax的東西,也許閱讀一些教程

+0

我試過這個,但是,按鈕被禁用,只是當我手動更新頁面不是 –

+0

然後,你需要在數據表中的ajax事件,主要是在過濾器,你'更新'commandButton – Kukeltje

+0

我已經嘗試了一個Ajax事件聽,但它也是一樣的 –