Theme
Exporter
This feature enables fully customizable exporter with the required functionalities with the help of Service Loader Concept.

Steps needs to follow:

  • Step 1: Create a folder named META-INF under resouces folder.Below META-INF folder create another folder called services.
  • Step 2: Creae a file with the name "ExporterFactory" as a service(Fully binary name of the service).
        Here it should be org.primefaces.extensions.component.exporter.ExporterFactory.
  • Step 3: Provide your own implementaions/providers of Exporter factory anywhere in your project.
        And copy the absolute path of custom exporter factory implementation in the ExporterFactory file
        How to do : Copy the file content of DefaultExporterFactory and rename the file as CustomExporterFactory.Copy the absolute path org.primefaces.extensions.showcase.util.CustomExporterFactory in ExporterFactory file.
  • Step 4: Copy the exporter implementations and add your own changes.And call these custom     implementations(Ex PDFCustomExporter,ExcelCustomExporter) instead built-in implmentations(Ex PDFExporter,ExcelExporter)

  • The below example demonstrates how the index column added using Custom Exporter feature.
    Basic Message Table-As At Date-22/07/2019
    SubjectTextTime
    subject 0text 01563827375462
    subject 1text 11563827375457
    subject 2text 21563827375453
    subject 3text 31563827375462
    subject 4text 41563827375458
    Export PDF and Excel
    Source
                    <p:dataTable id="messageTable" var="message" value="#{messageTableController.messages}"
                     paginator="true" rows="5" paginatorPosition="bottom"
                     filteredValue="#{messageTableController.filteredMessages}">
         <f:facet name="header">
              <h:outputText value="Basic Message Table"/>
              <h:outputText value="-As At Date-"/>
              <h:outputText value="#{messageTableController.currentDate}">
                 <f:convertDateTime pattern="dd/MM/yyyy"></f:convertDateTime>
              </h:outputText>
         </f:facet>
         <p:column filterBy="#{message.subject}" id="subject">
             <f:facet name="header">
                 <h:outputText value="Subject"/>
             </f:facet>
                <h:outputText value="#{message.subject}"/>
         </p:column>
         <p:column filterBy="#{message.text}">
             <f:facet name="header">
                    <h:outputText value="Text"/>
             </f:facet>
                <h:outputText value="#{message.text}"/>
         </p:column>
         <p:column filterBy="#{message.time}">
             <f:facet name="header">
                <h:outputText value="Time"/>
             </f:facet>
                <h:outputText value="#{message.time}"/>
         </p:column>
    </p:dataTable>
    
    
    <p:panel header="Export PDF and Excel">
         <p:commandLink id="pdf" ajax="false"  >
             <p:graphicImage value="/resources/images/pdf.png"/>
             <f:setPropertyActionListener value="true" target="#{exporterController.customExporter}" />
    
             <pe:exporter type="pdf" target="messageTable" fileName="MessagesTable"
                             />
    
         </p:commandLink>
    
         <p:spacer width="20"/>
    
         <p:commandLink id="xls" ajax="false"  >
             <p:graphicImage value="/resources/images/excel.png"/>
             <f:setPropertyActionListener value="true" target="#{exporterController.customExporter}" />
             <pe:exporter type="xlsx" target="messageTable" fileName="MessagesTable"
                             />
    
         </p:commandLink>
    
    </p:panel>
                
    Components and more
    Documentation pe:exporter
    Attributes (move mouse over the names to see data types)
    Name Description
    targetServer side id of the DataTable/DataList whose data would be exported.
    typeExport type: "pdf","xlsx".
    fileNameFilename of the generated export file, defaults to DataTable/DataList server side id.
    tableTitleTable/List header title to use.
    pageOnlyExports only current page instead of whole dataset.
    preProcessorPreProcessor for the exported document.
    postProcessorPostProcessor for the exported document.
    encodingCharacter encoding to use.
    selectionOnlyWhen enabled, only selection would be exported.
    subTableWhen enabled, subtable would be exported.
    facetBackgroundFacet background to use.Ex:Hex Colors like #FFFF00,#FF0000...
    facetFontSizeFacet font size to use.Ex:10,12..
    facetFontColorFacet font color to use.Hex Colors like #FFFF00,#FF0000...
    facetFontStyleFacet Font Style to use.Ex:normal,bold,italic.Default value is Bold
    fontNameFont Name/Font family to use.Ex:Courier New,Verdana..
    cellFontSizeCell Font size to use.Ex:10,12
    cellFontColorCell Font Color to use.Ex:Hex Colors like #FFFF00,#FF0000...
    cellFontStyleCell Font style to use.Ex:normal,bold,italic.Default value is normal
    datasetPaddingSpacing between multiple DataTables/DataLists
    orientationPDF format orientation.Possible values are Portrait or Landscape.Default value:Portrait
    skipComponentsThe list of components to be skipped in the pdf and excel export
    PrimeFaces Extensions Showcase - © 2011-2019, PrimeFaces: 7.0, PrimeFaces Extensions: 7.0.1, JSF: mojarra 2.3.2, Server: jetty/9.4.2.v20170220, Build time: 2019-05-21 21:46
    occured!
    Message:
    Timestamp:
    StackTrace: