DataExporter doesn't work since migration

UI Components for JSF
Post Reply
DaHocusPocus
Posts: 5
Joined: 01 Sep 2019, 18:56

17 Sep 2019, 10:25

Hi,

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);
				}
			}
		}
	}

DaHocusPocus
Posts: 5
Joined: 01 Sep 2019, 18:56

17 Sep 2019, 17:31

SOLVED : I migrated apache POI from 3.11 to 3.17
Dependencies to upgrade are not indicated in the Migration Guide of PrimeFaces.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

18 Sep 2019, 12:39

I will fix the upgrade guide. Thanks for pointing it out!
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

18 Sep 2019, 12:42

I just added it to the 6.1-6.2 Migration since that is where the version upgrade occurred: https://github.com/primefaces/primeface ... tion-Guide
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

AdamG
Posts: 1
Joined: 26 Jul 2023, 04:51

26 Jul 2023, 04:55

Hello, I'm having a similar issue with PrimeFaces 12 using POI-5.2.3. Is this the right version to use for PF 12, or might there be another library I am missing? The problem seemed to arise when I migrated to PrimeFaces 12, Java 17, and JSF-2

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

26 Jul 2023, 14:33

Code: Select all

 <!-- Data Exporter -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.2.3</version>
            <exclusions>
                <exclusion>
                    <groupId>com.github.virtuald</groupId>
                    <artifactId>curvesapi</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>batik-all</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.santuario</groupId>
                    <artifactId>xmlsec</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>de.rototor.pdfbox</groupId>
                    <artifactId>graphics2d</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcpkix-jdk15on</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk15on</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 48 guests