dataTable排序问题(JSF2.0 + primefaces) [英] dataTable sorting problem (JSF2.0 + primefaces)

查看:147
本文介绍了dataTable排序问题(JSF2.0 + primefaces)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么当我点击排序箭头时,我的dataTable没有对列进行排序。它只适用于我首先在过滤器上键入内容并将其擦除。(就像它需要在过滤器上至少有一个字符才能正确排序)。

I dont know why my dataTable does not sort the columns when i click on the sort arrow. It only works if i first type something on the filter and erase it.(It is like it needs to have at least one character on the filter to be able to sort correctly).

我会在这里粘贴代码:

这是带有dataTable的JSF页面

This is the JSF page with the dataTable

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:p="http://primefaces.prime.com.tr/ui">
    <ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">
<ui:define name="resultsForm">
<h:form enctype="multipart/form-data">
    <h:inputText id="search" value="" /><h:commandButton value="search"/>

    <p:dataTable var="garbage" value="#{resultsController.allGarbage}" dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"  
             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
             rowsPerPageTemplate="5,10,15">         

            <p:column filterBy="#{garbage.filename}" filterMatchMode="startsWith" sortBy="#{garbage.filename}" parser="string">  
            <f:facet name="header">  
            <h:outputText value="Filename" />  
            </f:facet>  
            <h:outputText value="#{garbage.filename}" />
             </p:column> 

            <p:column filterBy="#{garbage.description}" filterMatchMode="contains">  
            <f:facet name="header">  
            <h:outputText value="Description" />  
            </f:facet>  
            <h:outputText value="#{garbage.description}" />  
             </p:column> 

            <p:column sortBy="#{garbage.uploadDate}" parser="string">  
            <f:facet name="header">  
            <h:outputText value="Upload date" />  
            </f:facet>  
            <h:outputText value="#{garbage.uploadDate}" /> 
             </p:column>                
    </p:dataTable> 
</h:form>
</ui:define>

这里是与该页面交互的托管bean:

Here the managed bean that interacts with that page:

@ManagedBean
@ViewScoped implements Serializable
public class ResultsController {

@EJB
private ISearchEJB searchEJB;

private Garbage garbage;

public List<Garbage> getAllGarbage() {
    return searchEJB.findAllGarbage();
}

public Garbage getGarbage() {
    return garbage;
}

public void setGarbage(Garbage garbage) {
    this.garbage = garbage;
}   

访问数据库的EJB:

@Stateless(name = "ejbs/SearchEJB")
public class SearchEJB implements ISearchEJB {

@PersistenceContext
private EntityManager em;   
public List<Garbage> findAllGarbage() {
    Query query = em.createNamedQuery("findAllGarbage");
    List<Garbage> gList = new ArrayList<Garbage>();

    for (Object o : query.getResultList()) {
        Object[] cols = (Object[]) o;
        Garbage tmpG = new Garbage();
        tmpG.setFilename(cols[0].toString());
        tmpG.setDescription(cols[1].toString());
        tmpG.setUploadDate(cols[2].toString());

        gList.add(tmpG);
    }
    return gList;
}

}

使用了JPQL命名查询的实体:

The entity with the JPQL named query being used:

    @NamedQuery(name = "findAllGarbage", query = "SELECT g.filename, g.description,    g.uploadDate FROM Garbage g;")
    @Entity
    public class Garbage implements Serializable{

@Id
@GeneratedValue
@Column(nullable = false)
private Long id;
@Column(nullable = false)
private String filename;
@Column(nullable = false)
private String fileType;
@Column(nullable = false)
private String uploadDate;
@Column(nullable = false)
private String destroyDate;
@Lob
@Column(nullable = false)
private byte[] file;
@Column(nullable = false)
private String description;

带浏览器输出的打印屏幕

A print screen with browsers output

推荐答案

我想确认我遇到与primefaces-2.2.1描述的完全相同的问题。

I would like to confirm that I experience exactly the same problem described with primefaces-2.2.1.

我的dataTable的值(行元素)是从查询计算。

The value (row elements) of my dataTable are computed from a query.

对简单名称进行排序除非我也有filterBy,否则String属性会失败,即使这样,只有输入至少一个字母才能生效过滤箱。然后我可以在过滤结果中对升序/降序进行排序。

Sorting on a simple name String property fails unless I also have a filterBy, and even then it only works if I type in at least one letter into the filter box. Then I can sort ascending/descending within the filtered result.

Webel

这篇关于dataTable排序问题(JSF2.0 + primefaces)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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