Bonjour,
Je suis entrain de développer une application JEE.
Actuellement, j'essaye de modifier un fichier EXCEL (existant) avec Apache POI-12 et de télécharger ce dernier par l'appui sur un commandButton.Les outputs de mon ManagedBean fonctionnent parfaitement.
1/ Lorsque je désactive la propriété ajax du commandButton(ajax="false"), ce dernier ne fonctionne plus.
2/ Le téléchargement ne fonctionne pas.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 <p:commandButton id="fffc"  value="Download" ajax="false"  action="#{generateFileCtrl.download()}" >
 
                </p:commandButton>
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
 
  public void download() throws  IOException{
        System.out.println("you clicked download");
 
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("C:\\Users\\Info\\Desktop\\Annexe 30.xlsx")); 
XSSFSheet sheet = wb.getSheetAt(1);
 
  XSSFCell cell  = sheet.getRow(50).getCell(8);
 
  if(cell == null)
  {   System.out.println(" if(cell == null)");
      cell= sheet.getRow(50).createCell(8);
       cell.setCellType(Cell.CELL_TYPE_STRING);
       cell.setCellValue("a test");
     //  System.out.println("   cell.setCellValue(\"a test\"); done successfully !!");
  }
  //System.out.println(" the (cell is not  null)");
 cell.setCellType(Cell.CELL_TYPE_STRING);
       cell.setCellValue("a test");
 
   System.out.println("cell.setCellValue(\"a test\"); done successfully !!");       
            FileOutputStream  fileOut= new FileOutputStream ("C:\\Users\\Info\\Desktop\\Annexe 30.xlsx");
 
       wb.write(fileOut);    
 
 
             FacesContext facesContext = FacesContext.getCurrentInstance();
 
    ExternalContext externalContext = facesContext.getExternalContext();
    externalContext.setResponseContentType("application/projet");
    externalContext.setResponseHeader("Content-Disposition","attachment; filename=\""+ fileOut +"\"" );
externalContext.getResponseOutputStream();
 
 
 
    facesContext.responseComplete();
 System.out.println(" facesContext.responseComplete(); done succussfully !! ");       
 
 
}
Merci infiniment pour vos aides