Download link option is not working in display tag

1k views Asked by At

HiI am displaying table using displat tag library it is working fine but when i come to export links it is giving trouble so can any help how to do this one My code will be like this

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import = "com.preva.vo.StoppageDetails"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/displaytag.css" type="text/css">  
<link rel="stylesheet" href="css/screen.css" type="text/css">  
<link rel="stylesheet" href="css/site.css" type="text/css">  
<link href="css/sty.css" rel="stylesheet" type="text/css" />
<link href="css/tabborder.css" rel="stylesheet" type="text/css" />
</head>
<body>
<jsp:include page="Header.jsp" />
    <c:choose>
    <c:when test="${not empty trackingdetails}"> 
            <table id="display_table">
            <tr ><td style="text-align:center;"><b>Tracking Details</b></td></tr>
            <tr ><td style="text-align:center;"><b><%=request.getParameter("vehicleId") %></b></td></tr>
            <tr><td style="text-align:center;"> From &nbsp;<%=session.getAttribute("fromdate") %>&nbsp;to&nbsp;<%=session.getAttribute("startdate") %></td></tr>
            </table>
     <display:table id="deviceDetailsID" name="sessionScope.trackingdetails" pagesize="10" export="true" sort="list">
     <display:setProperty name="basic.empty.showtable" value="true" />
     <display:setProperty name="paging.banner.group_size" value="10" />
     <display:setProperty name="paging.banner.item_name" value="Record" />
     <display:setProperty name="paging.banner.item_names" value="Records" />

    <display:column property="serialID" title="Sl No" style="width: 3%"/>
    <display:column property="deviceID" title="DeviceID" style="width: 1%"/>
    <display:column property="datestamp" title="DATE" format="{0,date,dd-MM-yyyy}"/>
    <display:column property="timestamp" title="TIME" />
    <display:column property="speed" title="Speed"  />
    <display:column property="statuscode" title="Status Code"/>
    <display:column property="address" title="Address"  />
</display:table> 
</c:when>
<c:otherwise>
<jsp:include page="Pages/Trackingbody.jsp"/>
<div id="MenuLineDiv" style="width:100%; height: 2px; font-size: 2px; background-color: #FFCD44; position: relative; top: 0px;"></div>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
    <tr class="topheader">
        <td colspan="6" style="color:white;text-align:center;">Tracking report for <%=request.getParameter("vehicleId") %> from <%=session.getAttribute("fromdate") %> to <%=session.getAttribute("startdate") %> </td>
    </tr>


    <tr class="secondhedr">
        <td colspan="6" style="color:white;text-align:center;">No data found</td>
    </tr>

</table>
  </c:otherwise>
</c:choose> 
    <jsp:include page="Footer.jsp"/>        
</body>

</html>

When i click export 'csv' it is displaying in browser not as a file i.e it is not asking me to save or open the file option can any help Thanks in advance

1

There are 1 answers

3
Aniket Kulkarni On

In your code after

<display:setProperty name="paging.banner.item_names" value="Records" />

line add two properties

<display:setProperty name="export.pdf" value="true" /> //set false if you don't want
<display:setProperty name="export.csv" value="true" /> //set false if you don't want

Now, add two more properties to set download file name

<display:setProperty name="export.csv.filename" value="CSV Report.pdf"/>
<display:setProperty name="export.pdf.filename" value="PDF Report.pdf"/>