sortBy do primefaces não funciona - Usando Hibernate / JPA

Olá pessoal…
Estou postando aqui, porque realmente não encontrei a solução em lugar algum. Já estou 3 dias procurando. Já pesquisei no GOOGLE, aqui no FORUM GUJ e nada.

Já olhei no site http://www.primefaces.org/showcase-labs/ui/datatableSorting.jsf
porém, fiz exatamente igual… o dataTable funciona perfeitamente… porem, quando clica na coluna para ordenar, nada acontece. Apenas as setas da coluna que mudam de direção

alguem pode me ajudar? Obrigado!
Segue o código

[size=18]ordernar.xthml [/size]

<!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="pess" value="#{pessoaBean.listaPessoas}" rowKey="p.codigo">
			<p:column id="modelHeader" sortBy="#{pess.nome}">
				<f:facet name="header">
					<h:outputText value="Nome" />
				</f:facet>
				<h:outputText value="#{pess.nome}" />
			</p:column>
		</p:dataTable>
	</h:form>
</h:body>
</html>

[size=18]PessoaDAO.java [/size]

[code]
package dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import model.Pessoa;

[size=18] Pessoa.java[/size]

package model;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@Table(name="pessoas")
public class Pessoa implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(unique=true, nullable=false)
	private int codigo;

	@Column(nullable=false, length=100)
	private String nome;


	public int getCodigo() {
		return this.codigo;
	}

	public void setCodigo(int codigo) {
		this.codigo = codigo;
	}

	public String getNome() {
		return this.nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

}
public class PessoaDAO extends DAO {


        @SuppressWarnings("unchecked")
		public List<Pessoa> exibir(){
            EntityManager em = getEntityManager();
            try{
            		em.getTransaction().begin();
                    Query q = em.createQuery("select p from Pessoa p");
                    em.getTransaction().commit();
                    
                    return q.getResultList();
           }finally{
                    //em.close();
            }
    }
       
}


[size=18] PessoaBean.java[/size]

package bean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import dao.PessoaDAO;
import model.Pessoa;


@ManagedBean
@RequestScoped
public class PessoaBean  {
	
	private Pessoa pessoa = new Pessoa();
	private Pessoa selecionaPessoa; 
	private DataModel<Pessoa> modelPessoa;

  
	public Pessoa getPessoa() {
   		return pessoa;
   	}

   	public void setPessoa(Pessoa pessoa) {
   		this.pessoa = pessoa;
   	}
	
   	
 	public Pessoa getSelecionaPessoa() {
		return selecionaPessoa;
	}

	public void setSelecionaPessoa(Pessoa selecionaPessoa) {
		this.selecionaPessoa = selecionaPessoa;
	}

   	@SuppressWarnings({ "unchecked", "rawtypes" })
   	
	public DataModel getListaPessoas(){
        PessoaDAO pessoaDAO = new PessoaDAO();
        modelPessoa = new ListDataModel(pessoaDAO.exibir());

        System.out.println("Executando getTodos()");
        return modelPessoa;
   	}
}

Troca de RequestScope para ViewScope.

Já tinha feito isso…
mas ficou pior… pois nem as setas do sortBy funcionam.

Olá amigos…
consegui graças a esse topico

ou seja,
Evite carregar sua lista de dados nos getters. Tente uma chamada de inicialização no @PostConstruct para carregar os dados iniciais, pois quando eles são chamados muitas vezes resulta neste tipo de problema de classificação e desempenho. Algo assim…

        private List<Entidade> findAll;
        ....
	@PostConstruct
	public void construct() {
		//code
		findAll = seuEJB.findAll();
	}

	public List<Entidade> findAll(){
		return findAll;
	}
        ...

xhtml

<p:dataTable id="dataTable" value="#{seulBean.findAll()}" ...

agora esta ordenando… porém…
Caracteres acentuados estão sendo ordenados por ULTIMO… ou seja:
A
B
C

X
Y
Z
Á
É

alguem ja passou por isso

Bom, depois de mais alguns dias, consegui finalmente.
Tive que mudar tudo… e utilizar LazyDataModel()

Segue o codigo

package dao;


import java.util.ArrayList;  

import java.util.Iterator;  
import java.util.List;  
import java.util.Map;    

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import model.Pessoa;


import org.primefaces.model.LazyDataModel;  
import org.primefaces.model.SortOrder;  


public class LazyPessoaDataModel extends LazyDataModel<Pessoa> {  
      
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private List<Pessoa> datasource;  
      
	public LazyPessoaDataModel(List<Pessoa> datasource) {  
        this.datasource = datasource;  
    } 
      
    @Override  
    public Pessoa getRowData(String rowKey) {  
    	
    	 Integer id = Integer.valueOf(rowKey);
    	 
        for(Pessoa pessoa : datasource) {  
        	 if(id.equals(pessoa.getCodigo())){
                return pessoa;  
        	 }
        }  
  
        return null;  
    }  
  
    @Override  
    public Object getRowKey(Pessoa pessoa) {  
        return pessoa.getCodigo();  
    }  
  
    
    @SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
    public List load(int first, int pageSize, String sortField, SortOrder sortOrder, Map filters) {
		    List data = new ArrayList();
		    
		    System.out.println("Executando Load()");
		    EntityManagerFactory emf = Persistence.createEntityManagerFactory("projetoSistema");
		    EntityManager em = emf.createEntityManager();
		
		    // CRITERIA
		    CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
		    CriteriaQuery accountQuery = criteriaBuilder.createQuery(Pessoa.class);
		
		    
		    // FROM
		    Root from = accountQuery.from(Pessoa.class);
		
		    
		    //SORT
		    if(sortField != null) {
			    if (sortOrder == SortOrder.ASCENDING) {
			    	accountQuery.orderBy(criteriaBuilder.asc(from.get(sortField)));
			    }
			    else {
			    	accountQuery.orderBy(criteriaBuilder.desc(from.get(sortField)));
			    }
		    }
		
		    // FILTROS
		    List predicates = new ArrayList();
		    for(Iterator it = filters.keySet().iterator(); it.hasNext();) {
				    String filterProperty = (String) it.next(); // table column name = field name
				    String filterValue = (String) filters.get(filterProperty);
				
				    Expression literal = criteriaBuilder.literal((String)filterValue);
				    predicates.add(criteriaBuilder.like(from.get(filterProperty), literal));
		    }
		    accountQuery.where((Predicate[]) predicates.toArray(new Predicate[predicates.size()]));
		
		    
		    
		    // PAGINATE
		    data = em.createQuery(accountQuery).setFirstResult(first).setMaxResults(getPageSize()).getResultList();
		
		    
		    
		    // ROW COUNT
		    CriteriaQuery countQuery = criteriaBuilder.createQuery(Long.class);
		    countQuery.select(criteriaBuilder.count(countQuery.from(Pessoa.class)));
		    countQuery.where((Predicate[]) predicates.toArray(new Predicate[predicates.size()]));
		   
		    
		    
		    int rowCount = Integer.parseInt(em.createQuery(countQuery).getSingleResult().toString());
		    setRowCount(rowCount);
		
		    return data;
    }

	 
 }

BEAN

[code]package bean;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.model.LazyDataModel;

import dao.LazyPessoaDataModel;
import dao.PessoaDAO;

import model.Pessoa;

@ManagedBean
@ViewScoped // SESSION OU VIEW SCOPED PARA ORDENAR
public class PessoaBean implements Serializable {

private static final long serialVersionUID = 1L;


private LazyDataModel<Pessoa> lazyModel;
private Pessoa selectedPessoa;  

private List<Pessoa> listaPessoas;  


private Pessoa pessoa = new Pessoa();
PessoaDAO pessoaDAO = new PessoaDAO();


@PostConstruct   
protected void init() {  
		
	System.out.println("Executando INIT()");
      listaPessoas = pessoaDAO.exibirPessoas();
      lazyModel = new LazyPessoaDataModel(listaPessoas); // DATA SOURCE

}  

public LazyDataModel<Pessoa> getLazyModel() {  
	System.out.println("Executando getLazyModel()");

     return lazyModel;  
}  

public Pessoa getSelectedPessoa() {  
    return selectedPessoa;  
}  

public void setSelectedPessoa(Pessoa selectedPessoa) {  
    this.selectedPessoa = selectedPessoa;  
}  
  

public List<Pessoa> getListaPessoas(){
	
		System.out.println("Retornou Consulta em Cache");
        return listaPessoas;
}

}
[/code]

utilizando LazyDataModel só nao consegui fazer funcionar o FILTRO
quando digito alguma coisa no filtro, a tabela fica em BRANCO

alguma coisa esta errado no filtro… se alguem souber, agradeço

segue o codigo do LazyDataModel() - parte do filtro


  // FILTROS
		    List predicates = new ArrayList();
		    for(Iterator it = filters.keySet().iterator(); it.hasNext();) {
				    String filterProperty = (String) it.next(); // table column name = field name
				    String filterValue = (String) filters.get(filterProperty);
				
				    Expression literal = criteriaBuilder.literal((String)filterValue);
				    predicates.add(criteriaBuilder.like(from.get(filterProperty), literal));
		    }
		    accountQuery.where((Predicate[]) predicates.toArray(new Predicate[predicates.size()]));