PrimeFaces dataTable排序不工作 [英] PrimeFaces dataTable sorting not working

查看:241
本文介绍了PrimeFaces dataTable排序不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取PrimeFaces数据表组件的排序行为无法正常工作,我遇到麻烦。 (我正在使用PrimFaces 4.0,JSF 2.1.12和Tomcat 7.0。)据我所知,我看到的问题与PF数据表相关的任何其他问题报告/讨论不符。为了探索这个问题,我创建了一个基于ShowCase使用排序的dataTable示例的示例,复制了tableBean支持bean的ShowCase源代码(包括生成本示例的本地汽车数据;不涉及外部数据库访问)和支持汽车类。 xhtml也是ShowCase示例的非常接近的副本:

 <!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:p =http://primefaces.org/ui>
< h:head>
< / h:head>
< h:body>
< h:form>

< p:dataTable id =dataTablevar =carvalue =#{tableBean.carsSmall}>
< f:facet name =header>
Ajax排序
< / f:facet>

< p:column id =modelHeadersortBy =#{car.model}>
< f:facet name =header>
< h:outputText value =Model/>
< / f:facet>
< h:outputText value =#{car.model}/>
< / p:column>

< p:column sortBy =#{car.year}>
< f:facet name =header>
< h:outputText value =Year/>
< / f:facet>
< h:outputText value =#{car.year}/>
< / p:column>

< p:column sortBy =#{car.manufacturer}>
< f:facet name =header>
< h:outputText value =制造商/>
< / f:facet>
< h:outputText value =#{car.manufacturer}/>
< / p:column>

< p:column sortBy =#{car.color}>
< f:facet name =header>
< h:outputText value =Color/>
< / f:facet>
< h:outputText value =#{car.color}/>
< / p:column>
< / p:dataTable>

< / h:form>
< / h:body>
< / html>

当xhtml运行时,数据表显示,但只有一列显示为可用用于排序(即,使用标题中的向上/向下箭头图标)。



dataTable有两个问题:


  1. 只显示一个列(Year)可用于排序。 (Year是Car类中int类型的属性,而其他三列是String类型,因此问题的一个方面是String字段的sortBy =#{car.xxx}标记被忽略。)

  2. 年列实际上不可排序。点击Year标题的向上/向下箭头没有任何效果。当单击Year头时,会发生服务器回调,但是表未排序。我已经跟踪了在服务器回调期间发生的ELException,其中代码无法处理表达式#{car.0}。毫无疑问,0应该是年,失败的表达毫无疑问是为什么不进行排序。

任何帮助将不胜感激,为什么这个非常简单的例子(几乎逐字逐句地复制自ShowCase来源)试图使用PrimeFaces可排序的dataTable令我悲伤。

解决方案

删除这样的磅和卷曲括号:



从此:

 < p:column sortBy =#{car.manufacturer}> 

到这个

 code>< p:column sortBy =manufacturer> 

我有同样的问题,只是因为这个原因。


I am having trouble getting the PrimeFaces dataTable component's sort behavior to work as documented. (I am using PrimFaces 4.0, JSF 2.1.12, and Tomcat 7.0.) The problem I am seeing doesn't correspond to any of the other problem reports/discussions related to PF dataTable, as far as I can tell. To explore the problem I created an example based closely on the ShowCase example of using a sorted dataTable, copying the ShowCase source code for the tableBean backing bean (including the generation of local car data for the example; no external DB access is involved) and the supporting Car class. The xhtml is also a very close copy of the ShowCase example:

<!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:p="http://primefaces.org/ui">
    <h:head>
    </h:head>
    <h:body>
           <h:form>

               <p:dataTable id="dataTable" var="car" value="#{tableBean.carsSmall}">
                   <f:facet name="header">
                       Ajax Sorting
                   </f:facet>

                   <p:column id="modelHeader" sortBy="#{car.model}">
                       <f:facet name="header">
                           <h:outputText value="Model" />
                       </f:facet>
                       <h:outputText value="#{car.model}" />
                   </p:column>

                   <p:column sortBy="#{car.year}">
                       <f:facet name="header">
                           <h:outputText value="Year" />
                       </f:facet>
                       <h:outputText value="#{car.year}" />
                   </p:column>

                   <p:column sortBy="#{car.manufacturer}">
                       <f:facet name="header">
                           <h:outputText value="Manufacturer" />
                       </f:facet>
                       <h:outputText value="#{car.manufacturer}" />
                   </p:column>

                   <p:column sortBy="#{car.color}">
                       <f:facet name="header">
                           <h:outputText value="Color" />
                       </f:facet>
                       <h:outputText value="#{car.color}" />
                   </p:column>
               </p:dataTable>

           </h:form>
    </h:body>
</html>

When the xhtml is run, the data table shows up, but with only one column displayed as being available for sorting (i.e., with the up/down arrow icon in the header).

The dataTable has two problems:

  1. Only one of the columns (Year) is shown as usable for sorting. (Year is a property of type "int" in the Car class, whereas the other three columns are type String, so one aspect of the problem is that the sortBy="#{car.xxx}" tag is being ignored for String fields.)
  2. The Year column is, in fact, not sortable. Clicking on the up/down arrows of the Year header has no effect. A server callback does occur when the Year header is clicked on, but the table is not sorted. I have tracked down an ELException that occurs during the server callback, in which the code is failing to handle the expression "#{car.0}". That "0" should, no doubt, be "year", and the failed expression no doubt is why no sorting is happening.

Any help would be appreciated in figuring out why this very simple example (copied almost verbatim from the ShowCase sources) of trying to use a PrimeFaces sortable dataTable is giving me grief.

解决方案

remove the pound and curly bracket like this:

From this:

<p:column sortBy="#{car.manufacturer}">

To this

<p:column sortBy="manufacturer">

I had the same problem and it was simply because of that.

这篇关于PrimeFaces dataTable排序不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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