I migrated Primefaces frome 5.1 to 7.0. Since this migration the dataExporter doesn't work.
When I debugging this, the attribute preProcessor works but postProcessor does not run.
I do not have an error in the logs.
Edit : type="xml" and "csv" works but "xls" and "pdf" not.
Thank you in advance !
Below the code used :
Code: Select all
<h:form id="searchForm">
<p:tabView id="searchTabView" widgetVar="searchTabViewWidgetVar" dynamic="false">
<p:tab id="searchTab">
<!-- CONTENT -->
<p:fieldset id="searchResultsFieldSet" toggleable="true" collapsed="true" toggleSpeed="100"
widgetVar="searchResultFieldSetVar" styleClass="closed-fieldset">
<p:dataTable id="searchResultsTable" value="#{searchCtrl.searchResults}" var="results"
rowKey="#{result.id}" emptyMessage="Empty" selectionMode="single"
selection="#{searchCtrl.selected}" sortBy="#{search.date}"
sortOrder="descending" scrollable="true" >
<p:ajax event="rowSelect" immediate="true" partialSubmit="true" async="true"
update=":searchrForm:searchTabView:searchResultsPanel, :searchForm:searchTabView:btnPrint, :searchForm:searchTabView:btnRapportEnquete" />
<p:ajax event="rowDblselect"
immediate="true" partialSubmit="true" async="true"
listener="#{searchCtrl.onDbClickSelect}"
onstart="PF('loadingDlgVar').show();"
process="searchResultsTable" />
<p:column>
<!-- CONTENT -->
</p:column>
<p:column>
<!-- CONTENT -->
</p:column>
<p:column>
<!-- CONTENT -->
</p:column>
<p:column>
<!-- CONTENT -->
</p:column>
</p:dataTable>
<!-- CONTENT -->
<p:panelGrid id="searchResultsPanel"
<p:row>
<p:column style="text-align:right;margin:0px 0px 0px 0px;">
<p:commandButton id="resultExportButton"
value="Export résultats" icon="icon-export-excel" ajax="false"
disabled="#{searchCtrl.searchResults == null or empty searchCtrl.searchResults}">
<p:dataExporter type="xls" target="searchResultsTable"
fileName="search" preProcessor="#{searchCtrl.initExportResultsXls}"
postProcessor="#{searchCtrl.exportResultsXls}" />
</p:commandButton>
</p:column>
</p:row>
</p:panelGrid>
</p:fieldset>
</p:tab>
</p:tabView>
</h:form>
Code: Select all
public void initExportResultsXls(Object document) {
if (fullSearchResults.size() <= nbExportMax) {
searchResults = new ArrayList<TreDossier>(fullSearchResults);
} else {
searchResults = new ArrayList<TreDossier>(fullSearchResults.subList(0, nbExportMax));
}
}
Code: Select all
public void exportResultsXls(Object document) {
// reinitialisation de la liste de recherche
showSearchResult();
Workbook wb = (Workbook) document;
Sheet sheet = wb.getSheetAt(0);
Row header = sheet.getRow(0);
CellStyle hearderStyle = wb.createCellStyle();
hearderStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
hearderStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
Cell cell = header.getCell(i);
sheet.setColumnWidth(i, 6000);
cell.setCellStyle(hearderStyle);
}
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setWrapText(true);
DateFormat df = new SimpleDateFormat(IConstants.FR_SIMPLE_DATE_PATTERN, Locale.FRANCE);
CellStyle cellStyleDate = ExcelService.getInstance().createDateCellStyle(wb, IConstants.EXCEL_SIMPLE_DATE_PATTERN);
CellStyle cellStyleId = ExcelService.getInstance().createIdCellStyle(wb);
int nbRows = sheet.getLastRowNum();
if (nbRows > 1) {
for (int rowIndex = HEADER_ROW_INDEX; rowIndex <= nbRows; rowIndex++) {
Row row = sheet.getRow(rowIndex);
Iterator<Cell> itCell = row.cellIterator();
while (itCell.hasNext()) {
Cell cell = itCell.next();
if (cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getStringCellValue().contains("<br/>")) {
String cellValue = cell.getStringCellValue().replaceAll("<br/>", "\n");
cell.setCellValue(cellValue);
cell.setCellStyle(cellStyle);
}
ExcelService.getInstance().formatXlsDate(cell, cellStyleDate, df, IConstants.REGEX_SIMPLE_DATE_PATTERN);
ExcelService.getInstance().formatXlsFolderOrActionId(cell, cellStyleId);
}
}
}
}