2012-07-17 19 views
6

Hiện tại, tôi đang hiển thị siêu dữ liệu hình ảnh thành công từ cơ sở dữ liệu của mình bằng cách sử dụng dữ liệu có khả năng sắp xếp/lọc. Dưới đây, tôi có thể hiển thị thành công hình ảnh của mình bằng cách sử dụng hình ảnh của bên thứ ba (http://www.jacksasylum.eu/ContentFlow/). Tôi đang sử dụng cùng một danh sách để hiển thị cả hai tại thời điểm này. Sau khi tôi lọc dữ liệu của mình bên trong dữ liệu có thể định giá được, tôi cần cập nhật động danh sách hình ảnh của mình trong luồng của mình với các kết quả được lọc có thể lọc.Thủ tướng Lưu/Vượt qua Danh sách Kết quả được Lọc Dữ liệu

Cách tốt nhất để thực hiện việc này bằng PrimeFaces là gì? Có ai có thể chỉ cho tôi một ví dụ làm việc không?

Đây là mã của tôi:

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> 
............... 

Screenshot.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

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

    private List<Screenshot> screenshots; 

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

Trả lời

8

Tôi thấy điều này một que thú vị stion vì vậy tôi đã làm một số nghiên cứu. Đầu tiên tôi đã có một nụ cười tìm kiếm this. Sau đó, tôi tình cờ gặp this. Câu trả lời dường như là:

Thêm phần này vào <p:datatable>:

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

Trong đậu:

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; 
    } 
+0

Cảm ơn thông tin! Tôi đã thực hiện điều này và có thể hiển thị các kết quả được lọc trong một outputPanel! Hiện tại, tôi đã cố gắng hiển thị hình ảnh của các bản ghi đã chọn trong một datatable. Có vẻ như tôi gặp vấn đề với việc triển khai ContentFlow nằm ngoài phạm vi của câu hỏi này. Bạn có thể nhìn vào một trong đó ở đây: http://stackoverflow.com/questions/11660247/display-db-images-using-contentflow-coverflow-illegalstateexception-error Cảm ơn một lần nữa để được giúp đỡ của bạn !! – user1530469

+0

Rất vui khi biết rằng bạn đang tiến bộ. Nếu câu trả lời của tôi trả lời câu hỏi bạn đã hỏi, hãy đánh dấu câu trả lời là được chấp nhận, đó là tất cả những gì tôi cần ;-) Chào mừng bạn đến với stackoverflow bằng cách này. – siebz0r

0

Cảm ơn tất cả các ý kiến ​​trong việc này và một câu hỏi khác.

tôi sẽ chia sẻ giải pháp whith PrimeFaces 5.1:

public Map<String, Object> onFilter(AjaxBehaviorEvent event) { 
     System.out.println("FILTRAMOS LA TABLA"); 
     DataTable table = (DataTable) event.getSource(); 
     List<Actual> obj = table.getFilteredValue(); 

     listaActivosFijosFiltrados = obj; 

     if (obj != null) { 
      System.out.println("filtered = " + obj.size()); 
     } else { 
      System.out.println("No records found"); 
     } 

     Map<String, Object> filters = table.getFilters(); 
     return filters; 
    } 
Các vấn đề liên quan