Primefaces保存/传递已过滤的DataTable结果列表 [英] Primefaces Save/Pass Filtered DataTable Results List

查看:226
本文介绍了Primefaces保存/传递已过滤的DataTable结果列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我使用带有排序/过滤功能的数据库,从数据库中成功显示图像元数据。在我的数据表下方,我使用第三方图片覆盖流程成功显示我的图片( http://www.jacksasylum.eu / ContentFlow / )。在这一点上,我使用相同的列表来显示。在我的数据库中过滤我的数据后,我需要使用已过滤的数据表结果动态更新我的覆盖流中的图像列表。

Currently, I'm displaying image metadata successfully from my database using a datatable with sorting/filtering capabilities. Below my datatable I'm successfully displaying my images using a third party image coverflow (http://www.jacksasylum.eu/ContentFlow/). I'm using the same list to display both at this point. After I filter my data within my datatable I need to dynamically update my image list in my coverflow with the filtered datatable results.

使用PrimeFaces最好的方法是什么?任何人都可以指出我的工作实例吗?

What is the best way to do this using PrimeFaces? Would anyone be able to point me toward a working example?

这是我的代码:

screenshotData.xhtml

screenshotData.xhtml

<h:form>
        <p:dataTable var="scrshot" value="#{screenshots}" paginator="true" rows="8" 
                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
                 rowsPerPageTemplate="5,10,15" widgetVar="dataTable" draggableColumns="true"
                 emptyMessage="No screenshot data found with given criteria"> 
          <f:facet name="header"> 
            <p:outputPanel> 
                <h:outputText value="Search all fields:"/> 
                <p:inputText id="globalFilter" onkeyup="dataTable.filter()" style="width:150px" /> 
            </p:outputPanel> 
          </f:facet>
          <p:column headerText="Time" sortBy="#{scrshot.time}" filterBy="#{scrshot.time}" filterMatchMode="startsWith"> 
            <h:outputText value="#{scrshot.time}" /> 
          </p:column> 
          <p:column headerText="Id" sortBy="#{scrshot.id}" filterBy="#{scrshot.id}" filterMatchMode="startsWith"> 
            <h:outputText value="#{scrshot.id}" /> 
          </p:column> 
          <p:column headerText="User" sortBy="#{scrshot.user}" filterBy="#{scrshot.user}" filterMatchMode="startsWith"> 
            <h:outputText value="#{scrshot.user}" /> 
          </p:column>
          </p:dataTable>   
        </h:form>     
        <br/>
        <h:form>
          <p:outputPanel id="imgBlock" layout="block">
           <div class="ContentFlow"  style="width: 1400px; height: 500px" align="center">
            <div class="loadIndicator"><div class="indicator"></div></div>
            <div class="flow">
              <a4j:repeat var="img" value="#{screenshots}" rendered="true">
                 <div class="item">       
                     <img class="content" id="images" src="ImgServlet?id=#{img.id}" title="#{img.time}" draggable="true"/>
                     <div class="label">#{img.id}</div>
                  </div>
              </a4j:repeat>
             </div>         
           <div class="globalCaption"></div>
           <div class="scrollbar"><div class="slider"><div class="position"></div></div></div>
          </div>
         </p:outputPanel> 
       </h:form>   
...............

截图。 java

@Entity
@XmlRootElement
@Table(name="imgTable", uniqueConstraints = @UniqueConstraint(columnNames = "id"))
public class Screenshot implements Serializable, PhotoInterface {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
   private Long id;
   private String user;
   private Timestamp time;
-------- Getters/Setters ---------

ScreenshotListProducer.java

ScreenshotListProducer.java

@RequestScoped
public class ScreenshotListProducer {
   @Inject
   private EntityManager em;

   private List<Screenshot> screenshots;

   @Produces
   @Named
   public List<Screenshot> getScreenshots() {
      return screenshots;
   }


推荐答案

我发现这是一个有趣的问题所以我做了一些研究。首先,我笑了一下,发现这个。然后我偶然发现这个。答案似乎是:

I found this an interesting question so I did some research. First I had a laugh finding this. Then I stumbled upon this. The answer appears to be:

将此添加到< p:datatable>

<p:ajax event="filter" listener="#{bean.onFilter}" update = "@this"/>

在bean中:

public Map<String, String> onFilter(AjaxBehaviorEvent event) {
       DataTable table = (DataTable) event.getSource();
       List<Screenshot> obj =   table.getFilteredData();

       // Do your stuff here

       Map<String, String>  filters = table.getFilters();
       return filters;
   }

这篇关于Primefaces保存/传递已过滤的DataTable结果列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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