JSF/ICEFacesを使用しています。このページはICEFacesですが、ICEFacesのパフォーマンスが何らかの理由で遅いため、JSFデータテーブルを使用しています。とにかく、ICEFacesデータテーブルとは異なり、JSFテーブルにはExcel用のエクスポートが付属していないため、独自に作成しています。以下のようにApachePOIを使用することにしました。コードは正常に実行されますが、Excelファイルを保存するためのポップアップが表示されません。私は何かが足りないのですか?
public void ExportWithPoi(ActionEvent e) throws IOException{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
// ArrayList<PerfStatBean> statFilterResults;
Iterator<PerfStatBean> statsIterator = statFilterResults.iterator();
int i=0;
HSSFRow row;
row = sheet.createRow((short)0);
row.createCell((short)0).setCellValue("Current Application ID");
row.createCell((short)1).setCellValue("Event Name");
row.createCell((short)2).setCellValue("Generic Method Name");
while(statsIterator.hasNext()){
i++;
row = sheet.createRow((short)i);
PerfStatBean perfBean = statsIterator.next();
row.createCell((short)0).setCellValue(perfBean.getCurrent_appl_id());
row.createCell((short)1).setCellValue(perfBean.getCurrent_appl_id());
row.createCell((short)2).setCellValue(perfBean.getGeneric_method_name());
}
HttpServletResponse res = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
res.setContentType("application/vnd.ms-excel");
res.setHeader("Content-disposition", "attachment; filename=PerfCollector.xls");
try {
ServletOutputStream out = res.getOutputStream();
wb.write(out);
out.flush();
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
FacesContext faces = FacesContext.getCurrentInstance();
faces.responseComplete();
}
そして、Excelボタンは次のとおりです。
<h:commandButton id="excelBtn"
rendered="#{statsDisplayAndFilter.renderNextBtn}"
image="./xmlhttp/css/rime/css-images/excel.png"
actionListener="#{statsDisplayAndFilter.ExportWithPoi}"/>
ありがとう、
タム