mon probleme est qu'on choisit le rapport avec selectonemenu , la liste des bsc affiche mais la recuperation des valeurs est toujours null de selectmany meny , mon code est
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.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:a4j="http://richfaces.org/a4j"
      xmlns:p="http://primefaces.org/ui">
 
    <f:view contentType="text/html">
        <h:head>
            <f:facet name="first">
                <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
                <title>PrimeFaces</title>
            </f:facet>
        </h:head>
 
        <h:body>
 
            <p:layout fullPage="true">
 
 
 
                <p:layoutUnit position="center">
                    <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5"> 
                        <h:form id="form">
 
                            <h:outputText value="Report        " />  
                            <h:selectOneMenu id="rapport" value="#{exportBean.rapport}">  
                                <f:selectItem itemLabel="Select Report" itemValue="" /> 
                                <f:selectItems value="#{exportBean.report}" />  
                                <f:ajax render="bsc" execute="rapport"  listener="#{exportBean.handleCityChange()}" /> 
 
                            </h:selectOneMenu>
 
                                <h:outputText value="BSC Name: " />  
                                <h:selectManyMenu id="bsc" value="#{exportBean.selectItems}" converterMessage="true" style="width:150px;height:200px" >  
                                    <f:selectItems value="#{exportBean.selectItems}" var="player" itemLabel="#{player}" itemValue="#{player}" />  
                                    <f:ajax execute="rapport" listener="#{exportBean.get()}" event="valueChange"/>
                                </h:selectManyMenu>
 <h:commandButton value="submit" action="#{exportBean.get()}" type="submit" style="background-color:#040E0D0   ;font-weight: bold" >
 
                                    <f:ajax execute="rapport"  />  
                                </h:commandButton>
 
 
 
                                <h:outputText value="Segment Name: " />  
 
                                <h:inputText id="text" value="#{exportBean.text}">  
                                    <f:ajax execute="rapport" render="out"   
                                            listener="#{exportBean.complete()}"/>  
                                </h:inputText> 
 
                                <h:outputText value="Select Segment: " /> 
                                <h:selectManyMenu id="out" value="#{exportBean.cell}"  style="width:150px;height:200px" rendered="true"  >  
                                    <f:selectItem itemLabel="Select Segment " itemValue="" />
                                    <f:selectItems value="#{exportBean.listcell}"  />  
                                </h:selectManyMenu> 
 
                                <h:commandButton value="Generate" action="#{exportBean.create()}" type="submit" style="background-color:#040E0D0   ;font-weight: bold" >
 
                                    <f:ajax execute="rapport" render="reports" />  
                                </h:commandButton>
                                <h:commandButton id ="reports" action="#{exportBean.execute()}" value="download" />
 
                        </h:form>
                    </h:panelGrid> 
                    <h:panelGrid columns="3"> 
 
                    </h:panelGrid>
                </p:layoutUnit>
 
            </p:layout>
 
        </h:body>
 
    </f:view>
</html>
et le bean est
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;
 
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFHeader;
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.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import service.TunisianaPsCellBhService;
import persistance.TunisianaPsCellBhId;
@ManagedBean(name = "exportBean", eager = true)
@SessionScoped
public class exportBean implements Serializable{
   private String text;
   private String ss;
   private int count;
    private String rapport;
    private List<SelectItem> selectItems = new ArrayList<SelectItem>();
 
    public List<SelectItem> getSelectItems() {
        return selectItems;
    }
 
    private List <String> report=new LinkedList<String>();
private List <String> bsc=new LinkedList<String>();
private List <String> listbsc=new LinkedList<String>();
private List <String> cell=new LinkedList<String>();
private List <String> listcell=new LinkedList<String>();
private List <Object> listfinal=new LinkedList<Object>();
private List <ColumnModel> columns=new LinkedList<ColumnModel>();
private List <String> property=new LinkedList<String>();
 
    //public String[] bsc;
    public List<String> getBsc() {
        return bsc;
    }
 
    public void setBsc(List<String> bsc) {
        this.bsc = bsc;
    }
 
    public List<String> getCell() {
        return cell;
    }
 
    public void setCell(List<String> cell) {
        this.cell = cell;
    }
 
    public List<String> getProperty() {
        return property;
    }
 
    public void setProperty(List<String> property) {
        this.property = property;
    }
 
    public String getRapport() {
        return rapport;
    }
 
    public List<String> getReport() {
        report.add("TunisianaPsCellBh");
        return report;
    }
 
    /**
     * @param rapport the rapport to set
     */
    public void setRapport(String rapport) {
        this.rapport = rapport;
    }
 
    /**
     * @param report the report to set
     */
    public void setReport(List <String> report) {
        this.report = report;
    }
 
    /**
     * @return the bsc
     */
 
 
    /**
     * @return the listbsc
     */
 
 
    public int getCount() {  
        return count;  
    }  
 
    public void setCount(int count) {  
        this.count = count;  
    }  
 
    public void increment() {  
        count++;  
    }
    public List <String> getListbsc() {
 
 
          return listbsc;
 
    }
 
    /**
     * @param listbsc the listbsc to set
     */
    public void setListbsc(List <String> listbsc) {
        this.listbsc = listbsc;
    }
 
    /**
     * @return the cell
     */
 
 
    /**
     * @return the listcell
     */
    public List <String> getListcell() {
 
          return listcell;
 
    }
 
    /**
     * @param listcell the listcell to set
     */
    public void setListcell(List <String> listcell) {
        this.listcell = listcell;
    }
 
    /**
     * @return the bsc
     */
 
public void get()
{
    if (selectItems.size()==0)
    {
        System.out.println("selection vide");
    }
}
    public void complete() 
    {
        List l=null;
//        System.out.println(getBsc());
        try { 
            //System.out.println("complete "+rapport);
            System.out.println(selectItems.isEmpty());
            Class  classe = Class.forName ("service."+rapport+"Service");//instantiation du tunisana Ch cluster Bh
                          Object o = classe.newInstance();
                          Method method = classe.getMethod("select_segment",List.class,List.class,String.class);
                          listcell=(List<String>) method.invoke(o,l,bsc,text);
                      // listcell.add("bsc1");
              //  listcell.add("bsc2");    
 
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
 
        } catch (InstantiationException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } 
        catch (NoSuchMethodException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalArgumentException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
           Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
       }
    }
     public void handleCityChange() {  
 
 
             try {
                 System.out.println("handle"+rapport);
                List l=null;
            Class  classe = Class.forName ("service."+rapport+"Service");//instantiation du tunisana Ch cluster Bh
                          Object o = classe.newInstance();
                          Method method = classe.getMethod("select_bsc",List.class);
                        listbsc  =(List<String>) method.invoke(o,l);
                          for(int i=0 ; i<listbsc.size();i++)
                          {
                             selectItems.add(new SelectItem(listbsc.get(i),listbsc.get(i)));
                          }
              //  listbsc.add("bsc1");
              //  listbsc.add("bsc2");
 
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
 
        } catch (InstantiationException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchMethodException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalArgumentException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } 
 
    } 
 
    public static void main(String arg[])
    {
      try {
          List l=null;
            Class  classe = Class.forName ("service.TunisianaPsCellBh"+"Service");//instantiation du tunisana Ch cluster Bh
                          Object o = classe.newInstance();
                          Method method = classe.getMethod("select_segment",List.class);
                          method.invoke(o,l);
                          if(l!=null)
                          { for(int i=0;i<l.size();i++)
                          {
                              System.out.println(l.get(i));
                          }
                          }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
 
        } catch (InstantiationException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchMethodException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalArgumentException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        }     
    }
 
    /**
     * @return the text
     */
    public String getText() {
        return text;
    }
 
    /**
     * @param text the text to set
     */
    public void setText(String text) {
        this.text = text;
    }
 
    /**
     * @return the ss
     */
    public String getSs() {
        return ss;
    }
 
    /**
     * @param ss the ss to set
     */
    public void setSs(String ss) {
        this.ss = ss;
    }
 
    /**
     * @return the listfinal
     */
    public List <Object> getListfinal() {
        return listfinal;
    }
 
    /**
     * @param listfinal the listfinal to set
     */
    public void setListfinal(List <Object> listfinal) {
        this.listfinal = listfinal;
    }
    public String create()
    {
         try {
             //System.out.println(data[0]);
          List l=null;
         createDynamicColumns();
            Class  classe = Class.forName ("service."+rapport+"Service");//instantiation du tunisana Ch cluster Bh
                          Object o = classe.newInstance();
                          Method method = classe.getMethod("selection",List.class,List.class,List.class);
                         listfinal= (List<Object>) method.invoke(o,bsc,cell,l);
 
                           System.out.println(listfinal.get(1));
 
                          if(l!=null)
                          { for(int i=0;i<l.size();i++)
                          {
                              System.out.println(l.get(i));
                            listfinal.add(l.get(i));
                          }
                          }
                  return "list";
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
 
        } catch (InstantiationException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchMethodException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalArgumentException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        }     
     return null;
    }
 
     public void createDynamicColumns() {  
                       try {
          List l=new LinkedList();
 
                            createproperty();                            
            Class  classe = Class.forName ("service."+rapport+"Service");//instantiation du tunisana Ch cluster Bh
                          Object o = classe.newInstance();
                          Method method = classe.getMethod("select_column",List.class);
                         l= (List) method.invoke(o,l);
 
 
                          if(l!=null)
                          { for(int i=0;i<l.size();i++)
                          {
                            getColumns().add(new ColumnModel(l.get(i).toString().toUpperCase(),property.get(i).toString()));
                          }
                          }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
 
        } catch (InstantiationException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchMethodException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalArgumentException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        }     
     }
public void createproperty()
{
 try{
       List<String> l1=new LinkedList<String>();
       String v2;
 
       //appel de set de chaque cellule 
		   Class  pers = Class.forName ("persistance."+rapport+"Id");//instantiation du tunisana Ch cluster Bh
                          Object o1 = pers.newInstance();
                          Method method1 = pers.getMethod("create",List.class);
                          method1.invoke(o1,l1);	
 
 
                         if (l1==null){
                             System.out.println("erreur");
                         }
 
                          if(l1!=null)
                          { for(int i=0;i<l1.size();i++)
                          {
                              v2=l1.get(i);
                           String ch2=v2.substring(1);   //chaine sans la premiere lettre
			    		v2=v2.substring(0, 1);          //recup la premiere lettre
			    		v2=v2.toLowerCase();          // mise en maj
			    		v2+=ch2;
                                        property.add(v2);
                          }
                          }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
 
        } catch (InstantiationException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchMethodException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalArgumentException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } 
 
}
    /**
     * @return the columns
     */
    public List <ColumnModel> getColumns() {
        return columns;
    }
 
    /**
     * @param columns the columns to set
     */
    public void setColumns(List <ColumnModel> columns) {
        this.columns = columns;
    }
 public String execute() throws IOException {
	HSSFRow row = null;
	      HSSFCell cell = null;	// Création du fichier excel :
	try{	
             List<String> l=new LinkedList<String>();
     String fileName = "azerty.xls";
 
 
 
                 Workbook wb = new HSSFWorkbook();
        HSSFCellStyle styleHeader = (HSSFCellStyle) wb.createCellStyle();
                HSSFFont fontHeader = (HSSFFont) wb.createFont();
        fontHeader.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        styleHeader.setFont(fontHeader);
        Sheet sheet = wb.createSheet(fileName);
        rapport="TunisianaPsCellBh";
          Class  classe = Class.forName ("service."+rapport+"Service");//instantiation du tunisana Ch cluster Bh
                          Object o = classe.newInstance();
                          Method method = classe.getMethod("select_column",List.class);
                         l= (List) method.invoke(o,l);
        row = (HSSFRow) sheet.createRow((short) 0);
 
        for (int i = 0; i < l.size(); i++) {
            cell = row.createCell(i);
            cell.setCellValue(l.get(i));
            cell.setCellStyle(styleHeader);
        }
 
        int j = 1;
 
        for (int i = 0; i < listfinal.size(); i++) {
            row = (HSSFRow) sheet.createRow((short) j);
           String s= listfinal.get(i).toString();
            String str1[]= s.split(",");
            for (int k = 0; k < str1.length; k++) {
                HSSFCellStyle styleRow = (HSSFCellStyle) wb.createCellStyle();
                HSSFFont fontRow = (HSSFFont) wb.createFont();
                fontRow.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
                styleRow.setFont(fontRow);
                cell = row.createCell(k);
 
                cell.setCellValue(str1[k]);
                cell.setCellStyle(styleRow);
            }
 
            j++;
        }
 
		// Récupération de la réponse HTTP
		ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
		HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-disposition", "attachment; filename="+ fileName);
 
		// Ecriture de la réponse
		ServletOutputStream out = response.getOutputStream();
		wb.write(out);
		out.close();
 
		FacesContext.getCurrentInstance().responseComplete();
 
		return null;
                 }
         catch (ClassNotFoundException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
 
        }
        catch (InstantiationException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } 
        catch (NoSuchMethodException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (SecurityException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalArgumentException ex) {
            Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) { 
           Logger.getLogger(exportBean.class.getName()).log(Level.SEVERE, null, ex);
       } 
       return null;
	}
 
}