Nithyn. K
Nithyn. K

Reputation: 111

dataExporter (Excel and CSV) not exporting the dataTableCommandLink values - PrimesFaces and JSF

I have few columns in the Data Table which displays the column name and row values dynamically. But the first column in the data table have the values which has link. when we click that value it redirects to other screen.

Problem is when we export the csv/excel report. The first column which has this hyperlink not displaying the exact values. it shows as below in the excel

org.primefaces.component.column.Column@72d586ad - instead of exact value like "S123456789"

Please suggest how to display the exact value in the excel and csv.

<p:column headerText="#{msg['column.header']}" width="100" styleClass="columnLeft" filterBy="#{sampleDTO.linkNum}" sortBy="#{sampleDTO.linkNum}" id="linkNum">
                            
 <e:dataTableCommandLink id="viewTestLink" index="#{index}" value="#{sampleDTO.linkNum}" bean="#{sampleListBean}" action="viewLinkViewer"
                                                    ajax="false" currentDto="#{sampleDTO}"/>

</p:column>

Thanks in advance Nithyn K

Upvotes: 1

Views: 726

Answers (1)

Melloware
Melloware

Reputation: 12029

OK the reason its happening is because you are using a custom component <e:dataTableCommandLink which is why it can't figure out what text to display.

Here is what I would do use the ExportFunction...

  1. Create a custom exporter my example uses CDI.
@Named
@ApplicationScoped
public class PassthroughColumnExporter {

   public String export(final UIColumn column) {
      String value = StringUtils.EMPTY;
      for (final UIComponent child : column.getChildren()) {
         final Object exportValue = child.getAttributes().get("data-export");
         if (exportValue != null) {
            value = String.valueOf(exportValue);
            break;
         }
      }

      return value;
   }
}
  1. In your XHTML use this custom exporter to export the value you want looking for the data-export attribute.
<p:column exportFunction="#{passthroughColumnExporter.export}">
    <e:dataTableCommandLink value="#{row.displayValue}" data-export="#{row.exportValue}" />                 
</p:column>

Upvotes: 2

Related Questions