Search code examples
jspdisplaytag

DisplayTag Export is Exporting all bean fields


I'm using displaytag's Excel export with the ExcelHssfView to export a table as Excel. However, every field in the tables backing bean is being written out to the exported table, instead of just the defined columns. My displaytag configuration is:

export.types=excel
export.csv=false
export.pdf=false
export.excel=true
export.xml=false

export.excel.class=org.displaytag.export.excel.ExcelHssfView
export.excel.decorator=org.displaytag.sample.decorators.HssfTotalWrapper
export.ExcelView=org.displaytag.export.ExcelView

And in the jsp

    <display:setProperty name="export.excel" value="true" />
    <display:setProperty name="export.excel.filename" value="invoiceList.xls" />
    <display:setProperty name="export.amount" value="list" />
    <display:setProperty name="export.excel.include_header" value="true" />
    <display:setProperty name="export.excel.label" value="Download Invoices" />
</display:table>

Solution

  • All the <display:column> tags had their media attribute set to html, which prevented them from being referenced by the Excel export (expecting the all or excel media), so displaytag defaulted to passing in all the bean columns.

    <display:column media="html" headerClass="sortable"
                title="Invoice Amount" class="textDisplayArea" >
             $ <c:out value="${invoice.invoiceAmount}" /> 
    </display:column>
    

    changed to

    <display:column headerClass="sortable"
                title="Invoice Amount" class="textDisplayArea" >
             $ <c:out value="${invoice.invoiceAmount}" /> 
    </display:column>
    

    And it worked.