Salut tout le monde j'essaie d'exporter des données dynamique a un fichier excel a partir d'un DataTable,
voici le code de mon managed Bean
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
 
package com.project.managedbean;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
 
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.primefaces.event.FileUploadEvent;
 
import com.project.model.Categorie;
import com.project.service.ICategorieService;
 
 
@ManagedBean(name="listCategorieBean")
@ViewScoped
public class ListCategorieBean {
	@ManagedProperty(name="categorieService", value="#{categorieService}")
	private ICategorieService categorieService;
	//private List<Categorie>listCategorie;
	private String display2;
	private Categorie categSelectionne;
	private List<Categorie>listCategorie;
	private String urlAfficher;
	private String intitule;
	private String description ; 
	private int id;
	private String affiche;
	private String image;
	private String nomImage;
	private String destination2=".\\src\\main\\webapp\\pages\\css\\Photos";
 
	@PostConstruct
	public void init()
	{
		listCategorie=new ArrayList<Categorie>();
		System.out.println("je suis ici dans le init de la methode ListCategorie");	
		//List<Categorie>list=categorieService.listerALL();
		//Categorie c1=list.get(1);
		//System.out.println(c1.getIntitule());
		this.setListCategorie(categorieService.listerALL());
		display2="";	
 
	}
 
 
	public void delete()
	{
		System.out.println("je suis dans la methode delete");
		if(getCategSelectionne()==null)
		{
			System.out.println("nulllll,");
		}
		else{
		System.out.println(getCategSelectionne().getIntitule());
		getCategorieService().delete(getCategSelectionne().getIdCategorie());
		this.setListCategorie(categorieService.listerALL());
 
		}
 
	}
 
 
 
 
 
	//Exportation des donneee excel
//	
//	public void postProcessXLS(Object document) {  
//	    HSSFWorkbook wb = (HSSFWorkbook) document;  
//	    HSSFSheet sheet = wb.getSheetAt(0);  
//	    HSSFRow header = sheet.getRow(0);  
//	      
//	    HSSFCellStyle cellStyle = wb.createCellStyle();    
//	    cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);  
//	    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);  
//	      
//	    for(int i=0; i < header.getPhysicalNumberOfCells();i++) {  
//	        HSSFCell cell = header.getCell(i);  
//	          
//	        cell.setCellStyle(cellStyle);  
//	    }  
//	}
//	
 
 
 
 
	public String edit()
	{
		System.out.println("je suis dans la methode edit");
		System.out.println("voila l'enregistrement que je vais modifier : "+getCategSelectionne().getIntitule() );
		intitule=getCategSelectionne().getIntitule();
 
		id=getCategSelectionne().getIdCategorie();
		System.out.println(id);
		description=getCategSelectionne().getDescription();
		System.out.println(description);
		affiche=getCategSelectionne().getAffiche();
		System.out.println(affiche);
		image=getCategSelectionne().getImage();
		System.out.println(image);
//		FacesContext fc = FacesContext.getCurrentInstance();
//		getSession(fc).setAttribute("intitule",intitule);
		//getSession(fc).setAttribute("", arg1)
		return "modifCategorie?faces-redirect=true&amp;includeViewParams=true";
	}
 
 
 
	public String detail()
	{
		System.out.println("je suis dans la methode edit");
		System.out.println("voila l'enregistrement que je vais detailler : "+getCategSelectionne().getIntitule() );
        intitule=getCategSelectionne().getIntitule();
		id=getCategSelectionne().getIdCategorie();
		System.out.println(id);
		description=getCategSelectionne().getDescription();
		System.out.println(description);
		affiche=getCategSelectionne().getAffiche();
		System.out.println(affiche);
		image=getCategSelectionne().getImage();
		System.out.println(image);
		return "DetailCategorie?faces-redirect=true&amp;includeViewParams=true";
 
	}
 
 
 
//	
	public void edit2()
	{
		System.out.println("je suis dans la methode edit2");
 
		 String value = FacesContext.getCurrentInstance().
					getExternalContext().getRequestParameterMap().get("idCACHE");
		 System.out.println(value);
	}
 
 
 
 
	public void upload(FileUploadEvent event) {  
//      FacesMessage msg = new FacesMessage("Success! ", event.getFile().getFileName() + " is uploaded.");  
//      FacesContext.getCurrentInstance().addMessage(null, msg);
 
      FacesContext.getCurrentInstance().addMessage("growl", new FacesMessage("Successful", "L'image " + event.getFile().getFileName() + " A été uploader avec Succès"));
      // Do what you want with the file        
      try {
      	nomImage=event.getFile().getFileName();
      	System.out.println(nomImage);
 
          copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
      } catch (IOException e) {
          e.printStackTrace();
      }
 
  }
 
 
 
	 public void copyFile(String fileName, InputStream in) {
      try {
 
 
           // write the inputStream to a FileOutputStream
           OutputStream out = new FileOutputStream(new File(destination2 , fileName));
 
           int read = 0;
           byte[] bytes = new byte[1024];
 
           while ((read = in.read(bytes)) != -1) {
               out.write(bytes, 0, read);
           }
 
           in.close();
           out.flush();
           out.close();
 
//           FacesMessage msg = new FacesMessage("Success! ",  "Image is uploaded.");  
//           FacesContext.getCurrentInstance().addMessage(null, msg);
           } catch (IOException e) {
           System.out.println(e.getMessage());
           }
}
 
 
 
 
	public ICategorieService getCategorieService() {
		return categorieService;
	}
 
	public void setCategorieService(ICategorieService categorieService) {
		this.categorieService = categorieService;
	}
 
//Recuperer la session
 
	private HttpSession getSession(FacesContext fc){
		return (HttpSession) fc.getExternalContext().getSession(false);
	}
 
 
 
	public List<Categorie> getListCategorie() {
		return listCategorie;
	}
 
 
 
 
 
	public void setListCategorie(List<Categorie> listCategorie) {
		this.listCategorie = listCategorie;
	}
 
	public String getDisplay2() {
		return display2;
	}
 
 
	public void setDisplay2(String display2) {
		this.display2 = display2;
	}
 
 
	public Categorie getCategSelectionne() {
		return categSelectionne;
	}
 
	public void setCategSelectionne(Categorie categSelectionne) {
		this.categSelectionne = categSelectionne;
	}
 
	public String getUrlAfficher() {
		return urlAfficher;
	}
 
	public void setUrlAfficher(String urlAfficher) {
		this.urlAfficher = urlAfficher;
	}
 
 
 
 
	//getters and setters 
 
 
 
}
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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"> 
 
 
<h:head><title>Login page </title></h:head>
 
<link href="css/Shadow.css"  rel="stylesheet" type="text/css" />
<link href="css/buttonSearch.css"  rel="stylesheet" type="text/css" />
<script src="jquery/menu.js" type="text/javascript"></script>
<h:body>
 
<h:form id="formCategorie"  >
 
<p:panel styleClass="panExcel">
<h:outputLabel styleClass="labelPan" value="Gestion des Catégories : " />
 
 
 
 
 <p:commandLink  ajax="false">
         <p:graphicImage styleClass="excel" value="css/images/excel2.png"/>
         <p:dataExporter type="xls"  target="categorieTable" fileName="myexcel" />
</p:commandLink>
 
 
 
<p:graphicImage styleClass="separator" value="css/images/separator.jpg"/>
<p:graphicImage styleClass="search" value="css/images/search.png"/>
<p:graphicImage styleClass="add" value="css/images/add.png"/>
<p:graphicImage styleClass="trash" value="css/images/trash.png"/>
</p:panel> 
 
<p:panel id="panCategorie" styleClass="pan" style="padding-bottom:17px;" >
<h:panelGrid id="panpan">
<p:dataTable  var="categorie" rowKey="#{categorie.idCategorie}" paginator="true" rows="7" selection="#{listCategorieBean.categSelectionne}" selectionMode="single" id="categorieTable"  value="#{listCategorieBean.listCategorie}" emptyMessage="Aucune Catégorie n'a été trouvé">  
 
<f:facet name="header">  
Liste des Catégories
</f:facet> 
 
 
 
 <p:column  style="width:10px" >              
 
                    <p:selectBooleanCheckbox >  
                        <f:ajax execute="@this"  />
 
                    </p:selectBooleanCheckbox> 
 
</p:column>
 
        <p:column headerText="Id" sortBy="#{categorie.idCategorie}" style="width:40px"  filterBy="{categorie.idCategorie}" id="idCategorie" >  
         #{categorie.idCategorie} 
        </p:column>  
 
        <p:column headerText="Intitule" style="width:120px" sortBy="#{categorie.intitule}" filterBy="#{categorie.intitule}" id="intitule" >  
         #{categorie.intitule}
        </p:column> 
 
        <p:column headerText="Description" style="width:500px" sortBy="#{categorie.description}" filterBy="#{categorie.description}" id="description">  
           #{categorie.description}
        </p:column>
 
 
 
<p:column headerText="Afficher" sortBy="#{categorie.affiche}" style="width:20px"  id="affiche">  
<p:graphicImage value="css/images/#{categorie.affiche}" styleClass="imageTab"/>
</p:column>   
 
 
<p:column headerText="Actions" style="width:73px"  id="actions">
 
<p:commandLink action="#{listCategorieBean.edit}">
<p:graphicImage  value="css/images/eedit.png"/> 
<f:setPropertyActionListener value="#{categorie}" target="#{listCategorieBean.categSelectionne}" />
</p:commandLink>
 
<p:commandLink action="#{listCategorieBean.detail}">
<p:graphicImage value="css/images/detail2.png"/>
<f:setPropertyActionListener value="#{categorie}" target="#{listCategorieBean.categSelectionne}" />
</p:commandLink>
 
<p:commandLink oncomplete="catagDialog.show()" update=":formCategorie:display">
    <p:graphicImage value="css/images/loop.png"/>
   <f:setPropertyActionListener value="#{categorie}" target="#{listCategorieBean.categSelectionne}" /> 
</p:commandLink>
 
 
<p:commandLink    oncomplete="confirmDialog.show()" >
 <p:graphicImage  value="css/images/delete.png"/> 
<f:setPropertyActionListener value="#{categorie}" target="#{listCategorieBean.categSelectionne}" />
</p:commandLink>  
 
</p:column>   
 
</p:dataTable>
 
</h:panelGrid>
<p:confirmDialog  id="diag"  showEffect="bounce" hideEffect="explode" appendToBody="true" message="Est ce que vous êtes sur de vouloir supprimer cette catégorie?"
header="Confirmer la suppression de la catégorie" severity="alert"
widgetVar="confirmDialog"  >
 
<p:commandButton value="Oui" action="#{listCategorieBean.delete}"
 oncomplete="confirmDialog.hide()" update=":formCategorie:categorieTable">
</p:commandButton>
<p:commandButton value="Non"  onclick="confirmDialog.hide();" type="button" ajax="false" />
</p:confirmDialog>
<p:dialog header="Detail Catégorie" widgetVar="catagDialog"  appendToBody="true"  width="300" height="250" resizable="false"
               showEffect="bounce" hideEffect="fold"> 
 
 <h:panelGrid id="display" columns="2" cellpadding="4">  
 
              <f:facet name="header">  
                <p:graphicImage value="css/Photos/#{listCategorieBean.categSelectionne.image}" width="100" height="100"/>  
            </f:facet> 
 
            <h:outputText value="Id:" />  
            <h:outputText value="#{listCategorieBean.categSelectionne.idCategorie}" id="idCategorie"/>  
 
            <h:outputText value="Intitule:" />  
            <h:outputText value="#{listCategorieBean.categSelectionne.intitule}" id="intitule"/>  
 
            <h:outputText value="Description:" />  
            <h:outputText value="#{listCategorieBean.categSelectionne.description}" id="description"/>  
 
            <h:outputText value="Parent:" />  
            <h:outputText value="#{listCategorieBean.categSelectionne.intitule}" id="parent"/>  
        </h:panelGrid> 
</p:dialog>
 
</p:panel>
 
</h:form>
 
</h:body>
 
</html>
J'utilise primefaces 3.0
poi 3.7-beta1
jsf 2.1.6

le resultat ne correspond pas a ce qe j'attendais.
J'ai mon fichier excel mais les colonnes ne sont pas interprètès
j'ai toujours dans mes colonnes #{categorie.idCategorie}.......
J'ai besoin d'un coup de main SVP