原始数据可自定义排序具有动态列的功能 [英] Primefaces Datatable custom sort Function with dynamic columns

查看:144
本文介绍了原始数据可自定义排序具有动态列的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Primefaces 3.5,当我尝试使用动态列的自定义排序函数时,我会得到一个 PropertyNotFoundException

Using Primefaces 3.5, I get a PropertyNotFoundException when I try to use a custom sort function with dynamic columns.

我在xhtml文件中的datatable是(只显示相关代码)

My datatable in xhtml file is (just show the relevant code)

<p:dataTable id="dataTableVersioneMonitoraggio" var="row" value="# {monitoraggioBean.pacchetti}" 
                 rowKey="#{row.pacchetto.id}">

<p:columns value="#{monitoraggioBean.columns}" var="column"
           sortBy="#{row.celle[column.posizione].cella.valore}"
                sortFunction="#{monitoraggioBean.customSort}">               
  ...         
</p:columns>

</p:dataTable>

我的视图范围支持bean中的不完整的方法是:

The incomplete method in my view scope backing bean is:

public int customSort(Object val1, Object val2) {
    System.out.println("mySort" + val1 + "/" + val2);
    return 0;
}

问题是我无法在bean中达到这种方法,我得到以下错误:

The problem is I can't reach this method in the bean and I get the following errors:

GRAVE [javax.enterprise.resource.webcontainer.jsf.context] (http--0.0.0.0-8080-3) javax.el.PropertyNotFoundException: /monitoraggio.xhtml @80,161 sortFunction="#{monitoraggioBean.customSort}": The class 'com.packman.bean.MonitoraggioBean' does not have the property 'customSort'.

我已经尝试过使用p:column标签的自定义排序功能,它可以工作。

I have tried custom sort function with p:column tag and it works.

任何想法?

谢谢

推荐答案

我想出了一个解决方案/解决方法。我认为这是在p列标签和sortFunction属性上的Primefaces 3.5的错误。

I've come up with a solution/workaround. I think this is a bug of Primefaces 3.5 on p columns tag and sortFunction property.

Primefaces希望在 sortFunction =#{monitoraggioBean.customSort}上的方法表达式,但它希望对待它作为值表达式,并尝试找出getter / setter方法。

Primefaces expects a method expression on sortFunction="#{monitoraggioBean.customSort}" but it wants to treat it as value expression and tries to find out for getter/setter methods.

我的解决方法是在sortFunction中为name方法定义getter,并在支持bean中创建方法表达式。

My workaround is to define "getter" for the name method in sortFunction and to create the Method Expression in the backing bean.

public MethodExpression getOrdina() {
    FacesContext context = FacesContext.getCurrentInstance();
    return context.getApplication().getExpressionFactory().createMethodExpression(context.getELContext(), "#{monitoraggioBean.ordina}", Integer.class, new Class[]{Object.class, Object.class});
}

自定义排序的方法也必须在bean中定义: p>

The mehod for custom sorting has to be defined too in the bean:

public int customSort(Object val1, Object val2) {
    System.out.println("mySort" + val1 + "/" + val2);
    return 0;
}

以这种方式,当您点击列的标题时,首先getOrdina( )被调用然后customSort(...),您可以在其中实现排序逻辑。

In this way, when you click on the header of a column firstly getOrdina() is called and then customSort(...), where you can implement your sorting logic.

享受! :)

这篇关于原始数据可自定义排序具有动态列的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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