我不知道爲什麼我點擊排序箭頭時,我的dataTable不排序列。它只在我第一次在過濾器上輸入某些東西並刪除它時才起作用(這就像它需要在過濾器上至少有一個字符能夠正確排序)。dataTable排序問題(JSF2.0 + primefaces)
我會粘貼在這裏的代碼:
這是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與該頁面交互的JSF頁面:
@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;
}
使用
@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命名查詢實體:
訪問數據庫的EJB
@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;
打印屏幕與瀏覽器輸出
此外,我僅在頁面加載時使用 )測試了初始化列表,並且問題仍然存在,但該策略確保p:dataTable的其他特性,例如內聯cellEditor現在可以正常工作(如http://stackoverflow.com/questions/6365877/cell-edit-in-primefaces-is-not-updating-the-value中所述/ 6889504#6889504)。我認爲我們遇到了一個真正的bug,而不是濫用p:dataTable。 –
2011-07-31 12:39:53
我從來沒有修復那個。可能正如你所說我們正面臨一個錯誤,也許有不同版本的primefaces,情況就不同了。我仍然不知道如何解決它。 – sfrj 2011-07-31 13:04:16