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 xhtmlla 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 <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 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 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; } }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
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; } } }
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![]()
Partager