DataTable pagination

0 respostas
apocalipse

Olá.

Estou tentando usar o dataTable com paginação, mas não está funcionando.

Na página xhtml, o número de páginas é setado corretamente. O nome aparece na tela, mas quando tento ver o próximo nome a lista não é recaregada.

Se alguém tiver alguma sugestão.

Código:

package br.com.teste.dao;

    public class ListaGenericaDao {
    	
    	private Integer id;
    	private String nome;
    		
    	public ListaGenericaDao() {
    		
    	}
    	
    	public Integer getId() {
    		return id;
    	}

    	public void setId(Integer id) {
    		this.id = id;
    	}
    		
    	public String getNome() {
    		return nome;
    	}
    	
    	public void setNome(String nome) {
    		this.nome = nome;
    	}
    		
    }

package br.com.teste.view.pagination;

public class MontarPag extends LazyDataModel{

private MontarService service;
private String nome; 

public MontarVisaoPag (MontarService service){
	this.service = service;
}

@Override
public List<ListaGenericaDao> load(int first, int pageSize, String sortField,
		SortOrder sortOrder, Map<String, Object> filters) {
	List<ListaGenericaDao> result = service.lista(first, pageSize);
	
	int recordCount = result.size();
	setRowCount(recordCount);
	
	return result;
	
}

}

package br.com.teste.service;

@Stateless
public class MontarService  extends GenericService{
 
	public List<ListaGenericaDao> lista(Integer first, Integer pageSize) {
		List<ListaGenericaDao> r = new ArrayList<ListaGenericaDao>();
		
		Integer id = 0;
		
		ListaGenericaDao grupoAtual = null;
		Map<Integer, ListaGenericaDao> tmp = new HashMap<Integer, ListaGenericaDao>(); 
		for (Lista l:lst) {
			
			id = l.getId();
			
			if (!tmp.containsKey(id)) {
        		grupoAtual = new ListaGenericaDao();
        		
                       grupoAtual.setNome(l.getNome());
    			
        		r.add(grupoAtual);
        		tmp.put(id, grupoAtual);
        	}
			        	
		}
		
		return r;
		
	}
	
}

package br.com.teste.view;

@ManagedBean(name=montarMB)

@CustomScoped(value="#{keepAlive}")

public class MontarMB extends GenericView {
@EJB private MontarService montarVService;

private MontarPag pag;

@PostConstruct
public void post(){
	
}

public String init(){
	
	pag = new MontarPag(montarService);
			
	return null;
}

}

XMTML

<p:dataTable paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
    paginator="true"  reflow="true"  rows="1"  rowsPerPageTemplate="1, 2, 3, 4" lazy="true"  paginatorPosition="bottom" paginatorAlwaysVisible="false"
    styleClass="table table-striped table-bordered table-condensed wide"	
    rendered="#{montarMB.pag ne null}"
    value="#{montarMB.pag}" var="item">
        	<p:column>
        		<h:outputText value="#{item.nome}" />
        							    		  
        	</p:column>
        							    
    </p:dataTable>

Obrigado.

Criado 6 de junho de 2019
Respostas 0
Participantes 1