Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
Michael Anthony Dorrian
displaytag pagaing & export to excel,csv etc.. not working
12. Oktober 2009 07:59
Antwort

Michael Anthony Dorrian

Rang: Junior Member

Nachrichten: 89

Eintrittsdatum: 3. September 2009

Neue Beiträge

Basically I have my table being displayed in my portlet but although i can see my export options and also my pages nothing works when i click on it and i get redirected to my main portal previous page. Here is my code in my "View_funds.jsp" any help appreciated.

<%@ include file="/html/portlet/ext/library/init.jsp" %>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.TreeMap"%>
<%@taglib uri="http://displaytag.sf.net/el" prefix="display-el"%>
<%@page import="com.ext.portlet.library.action.FundData"%>


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

<%ArrayList fundsData = (ArrayList) FundData.GetFundData();FundData fund = null;
List testData = new ArrayList();
for (int i=0; i < fundsData.size(); i++) {
fund = (FundData) fundsData.get(i);
String field1 = fund.getFundCD();
String field2 = fund.getFundName();
Map map3 = new TreeMap();
map3.put("FundCD", field1);
map3.put("FundName", field2);
testData.add(map3);
}

session.setAttribute("test", testData);

%>

<jsp:scriptlet> request.setAttribute( "testData", testData ); </jsp:scriptlet>
<display:table name="testData" id="test" pagesize="15" export="true">

<display:column title="FundCD" property="FundCD"/>

<display:column title="FundName" property="FundName" />
<display:setProperty name="export.excel.filename" value="FundDetails.xls"/>
</display:table>
Michael Anthony Dorrian
[Resolved]RE: displaytag pagaing & export to excel,csv etc.. not working
15. Oktober 2009 20:53
Antwort

Michael Anthony Dorrian

Rang: Junior Member

Nachrichten: 89

Eintrittsdatum: 3. September 2009

Neue Beiträge

Michael Anthony Dorrian:
Basically I have my table being displayed in my portlet but although i can see my export options and also my pages nothing works when i click on it and i get redirected to my main portal previous page. Here is my code in my "View_funds.jsp" any help appreciated.

<%@ include file="/html/portlet/ext/library/init.jsp" %>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.TreeMap"%>
<%@taglib uri="http://displaytag.sf.net/el" prefix="display-el"%>
<%@page import="com.ext.portlet.library.action.FundData"%>


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

<%ArrayList fundsData = (ArrayList) FundData.GetFundData();FundData fund = null;
List testData = new ArrayList();
for (int i=0; i < fundsData.size(); i++) {
fund = (FundData) fundsData.get(i);
String field1 = fund.getFundCD();
String field2 = fund.getFundName();
Map map3 = new TreeMap();
map3.put("FundCD", field1);
map3.put("FundName", field2);
testData.add(map3);
}

session.setAttribute("test", testData);

%>

<jsp:scriptlet> request.setAttribute( "testData", testData ); </jsp:scriptlet>
<display:table name="testData" id="test" pagesize="15" export="true">

<display:column title="FundCD" property="FundCD"/>

<display:column title="FundName" property="FundName" />
<display:setProperty name="export.excel.filename" value="FundDetails.xls"/>
</display:table>


Fixed this issue....needed to specify which action was tied to the jsp page.

<display:table name="testData" id="test" pagesize="15" export="true" requestURI="/com/ext/portlet/library/action/ViewFundsAction">

The export csv and excel is not working correctly.....it shows the data in the portlet instead of showing a popup to download the data...
Jigna parag Joshi
RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo
7. April 2010 05:25
Antwort

Jigna parag Joshi

Rang: Junior Member

Nachrichten: 41

Eintrittsdatum: 9. Dezember 2008

Neue Beiträge

Hi,

I am using Liferay's Search Container for Organization searching..

now, i want to export this result to excelsheet...i think u ve done in your portlet..

can u give me some guidelines..


thanx,

Regards,
Jigna Joshi
Dhandapani S
RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo
14. Juni 2010 00:31
Antwort

Dhandapani S

Rang: Regular Member

Nachrichten: 156

Eintrittsdatum: 24. März 2009

Neue Beiträge

Hi Michael,

I am also facing the same problem, The export csv and excel is not working correctly.....it shows the data in the portlet instead of showing a popup to download the data...

Have you done this? if yes, please give me the solution for this.

Thanks in advance.

Dhandapani S
Jigna parag Joshi
RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo
22. Juni 2010 02:15
Antwort

Jigna parag Joshi

Rang: Junior Member

Nachrichten: 41

Eintrittsdatum: 9. Dezember 2008

Neue Beiträge

HI

I want to write file in response of portletAction class. i have write following code in EditUserAction class..

String linkShortCut = "\n";
linkShortCut = linkShortCut.concat("URL=" + loginLinkUrl + "\n");
String fileName = "LoginLink.URL";
ServletResponseUtil.sendFile(response,fileName,linkShortCut.getBytes(),ContentTypes.TEXT_PLAIN);

but, this doesn't show me File save dialog at client side...from my Action class i want to write file at clientside...I am generating dynamic file and that i want to give to client for d/w.
Krishna Melkote
RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo
24. November 2010 02:21
Antwort

Krishna Melkote

Rang: Junior Member

Nachrichten: 52

Eintrittsdatum: 22. September 2010

Neue Beiträge

Hi Dhandapani,

I see that this thread has been marked resolved. Did you manage to find a solution to your problem on this ? I am trying to do something similar and have hit the same issue!

Your response will be helpful!

Cheers
Dhandapani S
RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo
24. November 2010 22:03
Antwort

Dhandapani S

Rang: Regular Member

Nachrichten: 156

Eintrittsdatum: 24. März 2009

Neue Beiträge

Hi Krishna,

Still i didnt get resolve those issue. if i get solution, let u know

Regards

Dhandapani S
Krishna Melkote
RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo
23. Dezember 2010 04:20
Antwort

Krishna Melkote

Rang: Junior Member

Nachrichten: 52

Eintrittsdatum: 22. September 2010

Neue Beiträge

Hi,

I found a solution as below to do the export using displaytag from a portlet context

1. I have implemented a decorator as below to make the table we want to export available in session

 1
 2import javax.portlet.PortletSession;
 3import javax.servlet.jsp.PageContext;
 4
 5import org.apache.commons.logging.Log;
 6import org.apache.commons.logging.LogFactory;
 7import org.displaytag.decorator.TableDecorator;
 8import org.displaytag.model.TableModel;
 9
10public class PortletSessionDecorator extends TableDecorator {
11
12    private static Log LOGGER = LogFactory
13            .getLog("com.kris.portlets.ui.decorators");
14
15    @Override
16    public void init(PageContext pageContext, Object decorated,
17            TableModel tableModel) {
18
19        if (LOGGER.isDebugEnabled()) {
20            LOGGER.debug("TABLE ID : " + tableModel.getId());
21        }
22
23        // ---------------- Str portlet logic
24        // -----------------------------------
25
26        PortletSession pSession = (PortletSession) pageContext.getAttribute(
27                "portletSession", PageContext.PAGE_SCOPE);
28        pSession.setAttribute(tableModel.getId(), tableModel,
29                PortletSession.APPLICATION_SCOPE);
30
31        // ---------------- End portlet logic
32        // -----------------------------------
33
34        super.init(pageContext, decorated, tableModel);
35    }
36
37}


2. Implemented a controller to handle resource requests for export, code below. I just inherit from this controller wherever I need the export

  1
  2import java.io.IOException;
  3import java.io.Writer;
  4
  5import javax.portlet.PortletSession;
  6import javax.portlet.ResourceRequest;
  7import javax.portlet.ResourceResponse;
  8import javax.servlet.jsp.JspException;
  9
 10import org.apache.commons.logging.Log;
 11import org.apache.commons.logging.LogFactory;
 12import org.displaytag.export.CsvView;
 13import org.displaytag.export.ExcelView;
 14import org.displaytag.export.XmlView;
 15import org.displaytag.model.TableModel;
 16import org.springframework.stereotype.Controller;
 17import org.springframework.web.bind.annotation.RequestMapping;
 18import org.springframework.web.portlet.bind.annotation.ResourceMapping;
 19
 20 /*
 21 * Implements the basic Resource phases required for
 22 * exporting to XLS, CSV and XML
 23 *
 24 * Uses opensource library displaytag do the actual
 25 * export
 26 *
 27 */
 28
 29@Controller
 30@RequestMapping("VIEW")
 31public abstract class GenericExportingController {
 32
 33   
 34    private static final String TEXT_CSV = "text/csv";
 35   
 36    private static final String TEXT_XML = "text/xml";
 37   
 38    private static final String APPLICATION_VND_MS_EXCEL = "application/vnd.ms-excel";
 39   
 40    private static final String DOWNLOAD = " DOWNLOAD ";
 41   
 42    private static Log LOGGER = LogFactory.getLog("com.kris.portlets");
 43   
 44    /*
 45     * Handler for csv downloads
 46     */
 47    @ResourceMapping(value = "exportcsv")
 48    public void exportDataCsv(ResourceRequest request, ResourceResponse response) {
 49
 50   
 51        // Replicate export logic here from displaytag
 52        TableModel exportModel = (TableModel) request.getPortletSession()
 53                .getAttribute(request.getParameter("tableId"), PortletSession.APPLICATION_SCOPE);
 54       
 55        CsvView exportCsv = new CsvView();
 56        exportCsv.setParameters(exportModel, true, true, false);
 57       
 58       
 59        try {
 60            response.setContentType(TEXT_CSV);
 61            response.setProperty("Content-Disposition", "attachment;filename=\"" + "export.csv" + "\"");
 62            Writer writer = response.getWriter();
 63            exportCsv.doExport(writer);
 64
 65        } catch (IOException e) {
 66            e.printStackTrace();
 67        } catch (JspException e) {
 68            e.printStackTrace();
 69        }
 70    }
 71   
 72    /*
 73     * Handler for Excel downloads
 74     */
 75    @ResourceMapping(value = "exportxls")
 76    public void exportDataXls(ResourceRequest request, ResourceResponse response) {
 77
 78   
 79        // Replicate export logic here from displaytag
 80        TableModel exportModel = (TableModel) request.getPortletSession()
 81                .getAttribute(request.getParameter("tableId"), PortletSession.APPLICATION_SCOPE);
 82       
 83        ExcelView exportXls = new ExcelView();
 84        exportXls.setParameters(exportModel, true, true, false);
 85       
 86       
 87        try {
 88            response.setContentType(APPLICATION_VND_MS_EXCEL);
 89            response.setProperty("Content-Disposition", "attachment;filename=\"" + "export.xls" + "\"");
 90            Writer writer = response.getWriter();
 91            exportXls.doExport(writer);
 92
 93        } catch (IOException e) {
 94            e.printStackTrace();
 95        } catch (JspException e) {
 96            e.printStackTrace();
 97        }
 98    }
 99
100   
101    /*
102     * Handler for xml downloads
103     */
104    @ResourceMapping(value = "exportxml")
105    public void exportDataXml(ResourceRequest request, ResourceResponse response) {
106
107        // Replicate export logic here from displaytag
108        TableModel exportModel = (TableModel) request.getPortletSession()
109                .getAttribute(request.getParameter("tableId"), PortletSession.APPLICATION_SCOPE);
110       
111        XmlView exportXml = new XmlView();
112        exportXml.setParameters(exportModel, true, true, false);
113       
114       
115        try {
116            response.setContentType(TEXT_XML);
117            response.setProperty("Content-Disposition", "attachment;filename=\"" + "export.xml" + "\"");
118            Writer writer = response.getWriter();
119            exportXml.doExport(writer);
120
121        } catch (IOException e) {
122            e.printStackTrace();
123        } catch (JspException e) {
124            e.printStackTrace();
125        }
126    }
127   
128   
129}


3. In the view component(my case a jsp), I add these links manually. Do not enable the export option on the tag.
 1
 2<span>Export options : </span>
 3    <a href="<portlet:resourceURL escapeXml="false" id="exportcsv">
 4        <portlet:param name="tableId" value="eachResult"></portlet:param>
 5    </portlet:resourceURL>">CSV</a>
 6    <a href="<portlet:resourceURL escapeXml="false" id="exportxls">
 7        <portlet:param name="tableId" value="eachResult"></portlet:param>
 8    </portlet:resourceURL>">XLS</a>
 9    <a href="<portlet:resourceURL escapeXml="false" id="exportxml">
10        <portlet:param name="tableId" value="eachResult"></portlet:param>
11    </portlet:resourceURL>">XML</a>


"eachResult" is the tableid used in like

1
2<display:table id="eachResult">


That is it, you can now export to these 3 formats that displaytag supports or add new ones.

Hope this helps.

Cheers
Rajni Bharara
RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo
6. März 2012 22:23
Antwort

Rajni Bharara

Rang: New Member

Nachrichten: 1

Eintrittsdatum: 6. März 2012

Neue Beiträge

i Krishna,

Many Thanks for the solution , however, i couldnt able to set the TableModel in session attribute as this class is not Serializable class . is there is any way to deal with this ?? pls reply ASAP .

Regards,
Rajni