IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JSF Java Discussion :

[PrimeFaces / datatable] Pagination ne marche pas


Sujet :

JSF Java

  1. #1
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Novembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Novembre 2012
    Messages : 22
    Points : 17
    Points
    17
    Par défaut [PrimeFaces / datatable] Pagination ne marche pas
    Bonjour a tous

    je développe une application qui manipule un énorme volume de donnée. Mon environnement de développement est : spring 3+hibernate 4+jsf2+primefaces.
    Pour pouvoir gérer les données j'ai choisi la "lazyloading dataTable" de primefaces.

    Sauf que lors de l'execution, ca m'affiche uniquement les 10 premieres lignes de la BD. et si je veux passer a la page suivante ca marche pas.

    la page xhtml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    <html xmlns="http://www.w3.org/1999/xhtml"  
         xmlns:h="http://java.sun.com/jsf/html" 
         xmlns:f="http://java.sun.com/jsf/core" 
         xmlns:p="http://primefaces.org/ui">  
     
     <h:head><title>Welcome to JSF_PrimeFaces_Spring_Hibernate Project</title></h:head>  
     <body>  
     <f:view>  
         <h:form id="form">  
     
        <p:dataTable var="car" value="#{tableMB.lazyModel}" paginator="true" rows="10"  
                     paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"  
                     rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{tableMB.selectedCar}" id="carTable" lazy="true">  
     
            <p:ajax event="rowSelect" listener="#{tableMB.onRowSelect}" update=":form:display" oncomplete="carDialog.show()" />  
     
            <p:column headerText="Constructeur" sortBy="#{car.consi}" filterBy="#{car.consi}">  
                <h:outputText value="#{car.consi}" />  
            </p:column>  
     
            <p:column headerText="BSC" sortBy="#{car.nomBsc}" filterBy="#{car.nomBsc}">  
                <h:outputText value="#{car.nomBsc}" />  
            </p:column>  
     
            <p:column headerText="Cellule" sortBy="#{car.nomCell}" filterBy="#{car.nomCell}">  
                <h:outputText value="#{car.nomCell}" />  
            </p:column>  
     
     
        </p:dataTable>  
     
        <p:dialog header="Car Detail" widgetVar="carDialog" resizable="false"  
                  showEffect="explode" hideEffect="explode">  
     
            <h:panelGrid id="display" columns="2" cellpadding="4">  
     
     
     
                <h:outputText value="consi:" />  
                <h:outputText value="#{tableMB.selectedCar.consi}" style="font-weight:bold"/>  
     
                <h:outputText value="BSC:" />  
                <h:outputText value="#{tableMB.selectedCar.nomBsc}" style="font-weight:bold"/>  
     
                <h:outputText value="Cellule:" />  
                <h:outputText value="#{tableBean.selectedCar.nomCell}" style="font-weight:bold"/>  
     
            </h:panelGrid>  
        </p:dialog>  
     
    </h:form>  
     </f:view>  
    </body>    
    </html>
    la managedBean
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    package com.otv.managed.bean;
     
    import java.util.List;
     
    import javax.annotation.PostConstruct;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ManagedProperty;
    import javax.faces.bean.SessionScoped;
    import org.primefaces.model.LazyDataModel;
     
    import com.otv.model.Current;
    import com.otv.service.ICurrentService;
     
     
    @ManagedBean(name="tableMB")
    @SessionScoped
    public class TableBean {
     
    	@ManagedProperty(value="#{CurrentService}")
    	ICurrentService currentService;
     
    	private LazyDataModel<Current> lazyModel;   
        private Current selectedCar;  
        private List<Current> current;  
        public ICurrentService getCurrentService() {
    		return currentService;
    	}
     
    	public void setCurrentService(ICurrentService currentService) {
    		this.currentService = currentService;
    	}
     
    	  public TableBean() {  
     
    	        lazyModel = new LazyCellDataModel(current);  
    	    }  
     
     
    	  @PostConstruct
        public List<Current> getCurrent() {
        	return getCurrentService().ListeAll();
    		 // return current;
    	}
     
    	public void setCurrent(List<Current> current) {
    		this.current = current;
    	}
     
    	public Current getSelectedCar() {
    		return selectedCar;
    	}
    	public void setSelectedCar(Current selectedCar) {
    		this.selectedCar = selectedCar;
    	}
     
    	public LazyDataModel<Current> getLazyModel() {
     
    		lazyModel= new LazyCellDataModel(getCurrent());
    //		lazyModel = new LazyIdiomasDataModel(idiomasBo.findAllIdiomas());
    //        return lazyModel;
     
    		return lazyModel;
    	}
     
    	public void setLazyModel(LazyDataModel<Current> lazyModel) {
    		this.lazyModel = lazyModel;
    	}
     
     
     
     
     
     
     
    }
    la dataModel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    package com.otv.managed.bean;
     
    import java.io.Serializable;
    import java.util.ArrayList;
     
    import java.util.Collections;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
     
    import org.primefaces.model.LazyDataModel;
    import org.primefaces.model.SortOrder;
     
    import com.otv.model.Current;
     
    public class LazyCellDataModel extends LazyDataModel<Current> implements
    		Serializable {
     
    	private static final long serialVersionUID = 1L;
    	List<Current> dataSource;
    	private int pageSize;
    	private int rowIndex;
    	private int rowCount;
     
    	public List<Current> getDataSource() {
    		return dataSource;
    	}
     
    	public void setDataSource(List<Current> dataSource) {
    		this.dataSource = dataSource;
    	}
     
    	public LazyCellDataModel(List<Current> dataSource) {
    		this.dataSource = dataSource;
    	}
     
    	@Override
    	public Current getRowData(String rowKey) {
     
    		for (Current car : dataSource) {
    			if (car.getNomCell().equals(rowKey))
    				return car;
    		}
     
    		return null;
    	}
     
    	@Override
    	public Object getRowKey(Current car) {
    		return car.getNomCell();
    	}
     
    	@Override
    	public List<Current> load(int first, int pageSize, String sortField,
    			SortOrder sortOrder, Map<String, String> filters) {
    		List<Current> data = new ArrayList<Current>();
     
    		// filter
    		for (Current car : dataSource) {
    			boolean match = true;
     
    			for (Iterator<String> it = filters.keySet().iterator(); it
    					.hasNext();) {
    				try {
    					String filterProperty = it.next();
    					String filterValue = filters.get(filterProperty);
    					String fieldValue = String.valueOf(car.getClass()
    							.getField(filterProperty).get(car));
     
    					if (filterValue == null
    							|| fieldValue.startsWith(filterValue)) {
    						match = true;
    					} else {
    						match = false;
    						break;
    					}
    				} catch (Exception e) {
    					match = false;
    				}
    			}
     
    			if (match) {
    				data.add(car);
    			}
    		}
     
    		// sort
    		if (sortField != null) {
    			Collections.sort(data, new LazySorter(sortField, sortOrder));
    		}
     
    		// rowCount
    		int dataSize = data.size();
    		this.setRowCount(dataSize);
     
    		// paginate
    		if (dataSize > pageSize) {
    			try {
    				return data.subList(first, first + pageSize);
    			} catch (IndexOutOfBoundsException e) {
    				return data.subList(first, first + (dataSize % pageSize));
    			}
    		} else {
    			return data;
    		}
    	}
     
    }
    et le dao injecté dans la managedBean
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    package com.otv.dao;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import org.hibernate.SessionFactory;
     
    import com.otv.model.Current;
     
    public class CurrentDAO implements ICurrentDAO {
     
    	private SessionFactory sessionFactory;
     
    	public SessionFactory getSessionFactory() {
    		return sessionFactory;
    	}
     
    	public void setSessionFactory(SessionFactory sessionFactory) {
    		this.sessionFactory = sessionFactory;
    	}
     
    	@SuppressWarnings("unchecked")
    	public List<Current> listAll() {
    		List<Current> list = new ArrayList<Current>();
    		List<Object> maListe = new ArrayList<Object>();
     
    		maListe = getSessionFactory()
    				.getCurrentSession()
    				.createSQLQuery(
    						"select consi, nombsc,nombts, nomsite, lac, ci, nomcell from vcurrentcell")
    				.list();
    		for (int i = 0; i < maListe.size(); i++) {
     
    			// nombts, nomsite, lac, ci,
    			Object obj[] = (Object[]) maListe.get(i);
    			Current c = new Current();
    			c.setConsi(obj[0].toString());
    			c.setNomBsc(obj[1].toString());
    			c.setNomBts(obj[2].toString());
    			c.setNomSite(obj[3].toString());
    			c.setLac(obj[4].toString());
    			c.setCi(Integer.parseInt(obj[5].toString()));
    			c.setNomCell(obj[6].toString());
    			list.add(c);
    		}
     
    		return list;
    	}
     
     
    	public void onclick(int pageNum, int pageSize)
    	{
    		pageNum +=20;
    		pageSize+=20;
    	}
    }

    quelqu'un peut m'aider

  2. #2
    Nouveau Candidat au Club
    Homme Profil pro
    Architecte Logiciels
    Inscrit en
    Décembre 2012
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Architecte Logiciels

    Informations forums :
    Inscription : Décembre 2012
    Messages : 1
    Points : 1
    Points
    1
    Par défaut
    Bonjour,

    Pourquoi ne pas poser la question sur le forum officiel de Primefaces plutôt ? ( http://forum.primefaces.org/ ), il y a une grosse communauté derrière, pas mal douée en Primefaces, et tu auras surement plus de chance d'avoir une réponse qu'ici.

    Bon c'est en anglais... mais la doc de Primefaces aussi, donc je me dis que c'est pas un point bloquant.

    Sinon j'ai lu en diagonale le code, tu as essayé de débugger la méthode public List<Current> load(int first, int pageSize, ...) ? Vérifier qu'elle est bien appelée, quelles sont les valeurs de "first" et "pageSize" et si le résultat que tu retournes correspond auxdites valeurs ?

  3. #3
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Novembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Novembre 2012
    Messages : 22
    Points : 17
    Points
    17
    Par défaut Resolution du Probleme
    Bonjour
    j'ai fini par trouvé la solution!
    j'ai suivi ce petit tuto
    http://www.ke-cai.net/2011/10/pagina...l-loading.html

    j'espere que ca va aidé quelqu'un. Merci a tous et a tres bientot

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 16/11/2018, 16h04
  2. [PHP 5.0] Système d'auto pagination ne marche pas !
    Par Jean-Mouloud dans le forum Langage
    Réponses: 1
    Dernier message: 23/09/2012, 09h27
  3. primefaces : l'autocomplete ne marche pas
    Par olivier57b dans le forum JSF
    Réponses: 0
    Dernier message: 01/11/2010, 16h43
  4. Réponses: 19
    Dernier message: 22/07/2010, 18h40
  5. Tri et pagination du datagrid qui ne marche pas
    Par paradeofphp dans le forum ASP.NET
    Réponses: 2
    Dernier message: 30/05/2007, 18h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo