[
https://issues.apache.org/jira/browse/TOMAHAWK-980?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12501890
]
Emil Cazacu commented on TOMAHAWK-980:
--------------------------------------
I used this tag (locally modified) intensively, and I think I know how it would
fit exactly my needs:
using <f:facet name="excel">...</
to control exactly what I want to display.
This way is the most flexible way and no "guesing" is involved.
-------------------
<h:column>
<f:facet name="header">
<h:outputText value="GTIN" />
</f:facet>
<f:facet name="excel">
<t:outputText value="#{dataItem.gtin.gtin}" />
</f:facet>
... the rest of column tags
</h:column>
--------------------
I don't know how to code that.
> ExcelExport - corrections to Excel generation - when a commandLink on a column
> ------------------------------------------------------------------------------
>
> Key: TOMAHAWK-980
> URL: https://issues.apache.org/jira/browse/TOMAHAWK-980
> Project: MyFaces Tomahawk
> Issue Type: Bug
> Affects Versions: 1.1.5
> Environment: Suse 10.0
> Firefox 1.5.0.10
> apache-tomcat-5.5.20
> Reporter: Emil Cazacu
> Assignee: Cagatay Civici
> Fix For: 1.1.5
>
>
> Bugs:
> 1. - If my datatable has a commandLink, the value on it is not displayed e.g.
> <t:column>
> <f:facet name="header">
> <t:outputText value="Product" />
> </f:facet>
> <t:commandLink action="navToEditForProdus">
> <t:outputText value="#{dataItem.den}" />
> <t:updateActionListener property="#{XxxUIBean.id}"
> value="#{dataItem.id}" />
> </t:commandLink>
> </t:column>
> I know that this one can be overcome by using
> <t:commandLink action="navToEditForProdus" value="#{dataItem.den}"
> but I have tones of code, I do not want to have this one on my mind too.
> 2. - the header is not bold, (this is less important)
> I have the correction (JSE 5), working ok for me:
> in class ExcelExportPhaseListener.java
> /**
> * If it is null, simply adds an empty cell<br>
> * If it is a ValueHolder, adds empty cell with that value<br>
> * If it is a Command (link or button), tries to add the correct displayed
> * text - either on value attribute or in a ValueHolder child<br>
> */
> @SuppressWarnings("unchecked")
> private void addColumnValue(
> HSSFWorkbook workbook,
> HSSFRow rowHeader,
> UIComponent component,
> int index,
> boolean headerCell) {
> HSSFCell cell = rowHeader.createCell((short) index);
> cell.setEncoding(HSSFCell.ENCODING_UTF_16);
> if (headerCell) {
> // we make the line with the header in bold
> HSSFFont font = workbook.createFont();
> font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
> HSSFCellStyle style = workbook.createCellStyle();
> style.setFont(font);
> cell.setCellStyle(style);
> }
> String stringValue = null;
> if (component == null) {
> // null is the returned value
> stringValue = null;
> } else if (component instanceof ValueHolder) {
> stringValue =
> RendererUtils.getStringValue(FacesContext.getCurrentInstance(),
> component);
> } else if (component instanceof UICommand) {
> // to cope with the fact that the values of the links are not displayed
> UICommand cmd = (UICommand) component;
> if (cmd.getValue() != null) {
> // if that command has value attribute
> stringValue = "" + cmd.getValue();
> } else {
> // value attribute is null, so let's look in the children
> List<UIComponent> children = cmd.getChildren();
> for (int i = 0; i < children.size(); i++) {
> UIComponent child = children.get(i);
> if (child instanceof ValueHolder) {
> // we eventually found a component with a value, we use it
> stringValue =
> RendererUtils.getStringValue(FacesContext.getCurrentInstance(),
> child);
> break;
> }
> }
> }
> }
> if (stringValue != null) {
> cell.setCellValue(stringValue);
> }
> }
> The other methods modified to cope with the changes int the method
> addColumnValue(...).
> Only simple pass of "HSSFWorkbook workbook" or "boolean headerCell" -
> nothing more:
> // for header
> private void addColumnHeaders(HSSFWorkbook workbook, HSSFSheet sheet, List
> columns) {
> HSSFRow rowHeader = sheet.createRow(0);
> for (int i = 0; i < columns.size(); i++) {
> UIColumn column = (UIColumn) columns.get(i);
> addColumnValue(workbook, rowHeader, column.getHeader(), i, true);
> }
> }
> // for the other table
> private void addColumnValues(
> HSSFWorkbook workbook,
> HSSFSheet sheet,
> List columns,
> HtmlDataTable dataTable) {
> for (int i = 0; i < dataTable.getRowCount(); i++) {
> dataTable.setRowIndex(i);
> HSSFRow row = sheet.createRow(i + 1);
> for (int j = 0; j < columns.size(); j++) {
> UIColumn column = (UIColumn) columns.get(j);
> addColumnValue(workbook, row, (UIComponent)
> column.getChildren().get(0), j, false);
> }
> }
> }
> // the caller
> private HSSFWorkbook generateExcel(FacesContext facesContext, HtmlDataTable
> table) {
> HSSFWorkbook workbook = new HSSFWorkbook();
> HSSFSheet sheet = workbook.createSheet(table.getId());
> List columns = getColumns(table);
> int currentRowIndex = table.getRowIndex();
> addColumnHeaders(workbook, sheet, columns);
> addColumnValues(workbook, sheet, columns, table);
> table.setRowIndex(currentRowIndex);
> return workbook;
> }
>
> I looked on the repository, and the latest sources are with the bug.
> http://svn.apache.org/repos/asf/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/excelexport/ExcelExportPhaseListener.java
> Excel Exporter is a nice feature, and if there is anything I can do to help,
> please contact me.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.