ExcelExport doesn't populate column headers in Excel file
----------------------------------------------------------
Key: TOMAHAWK-911
URL: https://issues.apache.org/jira/browse/TOMAHAWK-911
Project: MyFaces Tomahawk
Issue Type: Bug
Affects Versions: 1.1.5-SNAPSHOT
Environment: Tomahawk 1.1.5-SNAPSHOT and Sandbox 1.1.5-SNAPSHOT
Reporter: Tara Peltier
See posting on mailing list:
http://www.nabble.com/ExcelExport-column-headers-in-Excel-file-tf3302286.html#a9185916
Body of posting pasted here:
I have found two areas where the behavior is unexpected, perhaps bugs?
1) If the dataTable has sortable=true, then none of the column headers get
exported at all.
2) If the column header uses a value-binding, it does not get exported to the
Excel worksheet in the first row. If the column header doesn't use a
value-binding, then the column header does get exported to the Excel worksheet.
-----------------------------------------------------------
Here's more details, as I downloaded the source for ExcelExport and debugged
into it, and I believe I have identified the problem area(s).
Problem 1)
In ExcelExportPhaseListener, the following method is used to convert each
"cell" in the datatable into a value for the Excel spreadsheet.
private void addColumnValue(HSSFRow rowHeader, UIComponent component, int
index) {
HSSFCell cell = rowHeader.createCell((short)index);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
if(component instanceof ValueHolder) {
String stringValue =
RendererUtils.getStringValue(FacesContext.getCurrentInstance(), component);
cell.setCellValue(stringValue);
}
}
When sortable=false on the datatable, the component passed to addColumnValue is
of type HtmlOutputText. However, when sortable=true on the datatable, Tomahawk
automatically wraps each column with a sortable header and so the component
presented to ExcelExport is of type
org.apache.myfaces.custom.sortheader.HtmlCommandSortHeader. This fails the
"if(component instanceof ValueHolder)" check and so doesn't even try to get the
value from the column.
Problem 2)
The problem revolves around the following line from the method pasted above
(ExcelExportPhaseListener.addColumnValue):
String stringValue =
RendererUtils.getStringValue(FacesContext.getCurrentInstance(), component);
If the column header is defined without using a value binding then the
following line in ExcelExportPhaseListener.addColumnValue is evaluated
correctly and returns the expected value.
E.g., for a column header like this
<t:column>
<f:facet name="header"><h:outputText value="TEST COLUMN NAME" /></f:facet>
<h:outputText value="#{trans.id}" />
</t:column>
the value evaluted by String stringValue =
RendererUtils.getStringValue(FacesContext.getCurrentInstance(), component); is
"TEST COLUMN NAME"
and the generated Excel file contains TEST COLUMN NAME in the first row.
However, if the column header is defined with a value binding (to a messages
file for example) then the following line in
ExcelExportPhaseListener.addColumnValue is evaluated incorrectly and returns an
empty string.
E.g., for a column header like this
<t:column>
<f:facet name="header"><h:outputText value="#{messages.trans_id}" /></f:facet>
<h:outputText value="#{trans.id}" />
</t:column>
the value evaluted by String stringValue =
RendererUtils.getStringValue(FacesContext.getCurrentInstance(), component); is
"" and the generated Excel file contains an empty string in the first row.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.