Search code examples
javaservletsdisplaytag

Export with displaytag


I am using displaytag tag library to export the data, but my data is coming out like this:

<a href=../status?status_index="78190" /a>

However I want the HTML markup to be stripped during the export, so that only the actual data is exported.

For example, I want the only data not the url should be like: 78190

Code:

<display:table name="bulkDetails" export="true" pagesize="100" id="row" sort="list">
    <display:column title="REQUESTID" sortable="true">
        <c:url value="../Status" var="url">
            <c:param name="Status_Index" value="${row.REQUESTID}"/>
        </c:url>
        <a href=${url}>${row.REQUESTID}</a>
    </display:column> 

My displaytag.properties looks like this:

basic.empty.showtable=true 
export.excel=true 
export.csv=true 
export.xml=false 
export.pdf=false 
export.excel.class=org.displaytag.export.ExcelView 
#export.excel.class=org.displaytag.export.CsvView 
# if set, file is downloaded instead of opened in the browser window 
export.excel.filename=report.xls 
export.csv.include_header=true 
export.csv.filename=report.csv

Solution

  • You will need to define different media types for your display and for your export columns:

    <display:table name="bulkDetails" export="true" pagesize="100" id="row" sort="list">
        <display:column title="REQUESTID" sortable="true" media="html">
            <c:url value="../Status" var="url">
                <c:param name="Status_Index" value="${row.REQUESTID}"/>
            </c:url>
            <a href=${url}>${row.REQUESTID}</a>
        </display:column> 
    
        <display:column title="REQUESTID" sortable="true" media="excel">
            ${row.REQUESTID}
        </display:column> 
    

    Essentially this is a duplication of the same column, in browser it will have a REQUESTID wrapped in a link, and in the exported version it will just contain the actual number.

    There's a similar question here: DisplayTag Export and Links