【问题标题】:Primefaces datatable multiple selection mode - lazy load fetchPrimefaces 数据表多选模式 - 延迟加载获取
【发布时间】:2012-09-25 07:03:09
【问题描述】:

在数据表上,我启用了多选复选框。 还有提交按钮,在 actionlistener 上,我将重复记录作为选定项目。

例如,第一页有 5 条记录,总记录数为 10,则第一页记录被复制两次,结果为 10 条记录,应限制为 5 条记录。

下面是sn-p的代码:

<p:dataTable id="sampleDataTable" var="_task" value="#{myBean.lazyModelTasks}"
             styleClass="dataTable" paginator="true" paginatorTemplate="{PageLinks}"
             paginatorPosition="bottom" rows="5" widgetVar="dataTab"             
             paginatorAlwaysVisible="true" rowIndexVar="rowIndex" 
             lazy="true"  selection="#{myBean.selectedItems}" 
             emptyMessage="No Search Results found !">  

    <p:column selectionMode="multiple" style="width:15px;">  
        <f:facet name="header"> 
        <h:outputText value="Sno" /> 
        </f:facet>
    </p:column>
 </p:dataTable> 

 <p:commandButton id="submit" value="Select" update="#{rerenderid}"
  actionListener="#{myBean.addSelectedItems}" oncomplete="#{onlinkclick}">
  <f:attribute name="selectedItems" value="#{myBean.selectedItems}"/>
 </p:commandButton>

托管 Bean 代码:

 public void addExternalRecipients(ActionEvent event) { 
      //THIS GIVES ME 10 RECORDS, THOUGH THERE ARE ONLY 5 RECORDS AT THAT INSTANCE
      this.selectedItems = (Address[])   
                         event.getComponent().getAttributes().get("selectedItems"); 
   }

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    也许不是解决方案,但您不需要使用事件来获取所选项目,我假设您的托管 bean 中有这个:

    private Address[] selectedItems;
    

    您还应该将 selectionMode="multiple" 放在数据表上,而不是像您正在做的那样放在列上,如下所示:

    <p:dataTable id="sampleDataTable" var="_task" value="#{myBean.lazyModelTasks}"
                 styleClass="dataTable" paginator="true"
                 paginatorTemplate="{PageLinks}"
                 paginatorPosition="bottom" rows="5" widgetVar="dataTab"             
                 paginatorAlwaysVisible="true" rowIndexVar="rowIndex" 
                 lazy="true"  selection="#{myBean.selectedItems}" 
                 selectionMode="multiple" <!--to make multiple rows selected -->
                 emptyMessage="No Search Results found !"> 
    

    然后,无需添加操作事件,所选实体将自动设置在您的托管 bean 上。当您进行提交(或 ajax 调用)时,您应该获得正确数量的选定实体。

    【讨论】:

    • 我不确定旧的 primefaces 版本是否像这样,但在今天看来,这个答案并不能正确回答这个问题。 selectionMode="multiple" 可以选择行。该问题要求选择复选框。为像我这样遇到这个问题的人写这篇评论:)
    猜你喜欢
    • 2013-01-09
    • 2016-11-02
    • 2013-06-17
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-07
    相关资源
    最近更新 更多