Foros de discusión

displaytag pagaing & export to excel,csv etc.. not working

Michael Anthony Dorrian, modificado hace 14 años.

displaytag pagaing & export to excel,csv etc.. not working

Junior Member Mensajes: 98 Fecha de incorporación: 3/09/09 Mensajes recientes
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, modificado hace 14 años.

[Resolved]RE: displaytag pagaing & export to excel,csv etc.. not working

Junior Member Mensajes: 98 Fecha de incorporación: 3/09/09 Mensajes recientes
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...
thumbnail
Jigna parag Joshi, modificado hace 14 años.

RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo

Junior Member Mensajes: 41 Fecha de incorporación: 9/12/08 Mensajes recientes
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
thumbnail
Dhandapani S, modificado hace 13 años.

RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo

Regular Member Mensajes: 176 Fecha de incorporación: 24/03/09 Mensajes recientes
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
thumbnail
Jigna parag Joshi, modificado hace 13 años.

RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo

Junior Member Mensajes: 41 Fecha de incorporación: 9/12/08 Mensajes recientes
HI

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

String linkShortCut = "[InternetShortcut]\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.
thumbnail
Krishna Melkote, modificado hace 13 años.

RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo

Junior Member Mensajes: 52 Fecha de incorporación: 22/09/10 Mensajes recientes
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
thumbnail
Dhandapani S, modificado hace 13 años.

RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo

Regular Member Mensajes: 176 Fecha de incorporación: 24/03/09 Mensajes recientes
Hi Krishna,

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

Regards

Dhandapani S
thumbnail
Krishna Melkote, modificado hace 13 años.

RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo

Junior Member Mensajes: 52 Fecha de incorporación: 22/09/10 Mensajes recientes
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


import javax.portlet.PortletSession;
import javax.servlet.jsp.PageContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.displaytag.decorator.TableDecorator;
import org.displaytag.model.TableModel;

public class PortletSessionDecorator extends TableDecorator {

	private static Log LOGGER = LogFactory
			.getLog("com.kris.portlets.ui.decorators");

	@Override
	public void init(PageContext pageContext, Object decorated,
			TableModel tableModel) {

		if (LOGGER.isDebugEnabled()) {
			LOGGER.debug("TABLE ID : " + tableModel.getId());
		}

		// ---------------- Str portlet logic
		// -----------------------------------

		PortletSession pSession = (PortletSession) pageContext.getAttribute(
				"portletSession", PageContext.PAGE_SCOPE);
		pSession.setAttribute(tableModel.getId(), tableModel,
				PortletSession.APPLICATION_SCOPE);

		// ---------------- End portlet logic
		// -----------------------------------

		super.init(pageContext, decorated, tableModel);
	}

}



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


import java.io.IOException;
import java.io.Writer;

import javax.portlet.PortletSession;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.servlet.jsp.JspException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.displaytag.export.CsvView;
import org.displaytag.export.ExcelView;
import org.displaytag.export.XmlView;
import org.displaytag.model.TableModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

 /*
 * Implements the basic Resource phases required for 
 * exporting to XLS, CSV and XML
 * 
 * Uses opensource library displaytag do the actual 
 * export
 * 
 */

@Controller
@RequestMapping("VIEW")
public abstract class GenericExportingController {

	
	private static final String TEXT_CSV = "text/csv";
	
	private static final String TEXT_XML = "text/xml";
	
	private static final String APPLICATION_VND_MS_EXCEL = "application/vnd.ms-excel";
	
	private static final String DOWNLOAD = " DOWNLOAD ";
	
	private static Log LOGGER = LogFactory.getLog("com.kris.portlets");
	
	/*
	 * Handler for csv downloads
	 */
	@ResourceMapping(value = "exportcsv")
	public void exportDataCsv(ResourceRequest request, ResourceResponse response) {

	
		// Replicate export logic here from displaytag
		TableModel exportModel = (TableModel) request.getPortletSession()
				.getAttribute(request.getParameter("tableId"), PortletSession.APPLICATION_SCOPE);
		
		CsvView exportCsv = new CsvView();
		exportCsv.setParameters(exportModel, true, true, false);
		
		
		try {
			response.setContentType(TEXT_CSV);
			response.setProperty("Content-Disposition", "attachment;filename=\"" + "export.csv" + "\"");
			Writer writer = response.getWriter();
			exportCsv.doExport(writer);

		} catch (IOException e) {
			e.printStackTrace();
		} catch (JspException e) {
			e.printStackTrace();
		}
	}
	
	/*
	 * Handler for Excel downloads
	 */
	@ResourceMapping(value = "exportxls")
	public void exportDataXls(ResourceRequest request, ResourceResponse response) {

	
		// Replicate export logic here from displaytag
		TableModel exportModel = (TableModel) request.getPortletSession()
				.getAttribute(request.getParameter("tableId"), PortletSession.APPLICATION_SCOPE);
		
		ExcelView exportXls = new ExcelView();
		exportXls.setParameters(exportModel, true, true, false);
		
		
		try {
			response.setContentType(APPLICATION_VND_MS_EXCEL);
			response.setProperty("Content-Disposition", "attachment;filename=\"" + "export.xls" + "\"");
			Writer writer = response.getWriter();
			exportXls.doExport(writer);

		} catch (IOException e) {
			e.printStackTrace();
		} catch (JspException e) {
			e.printStackTrace();
		}
	}

	
	/*
	 * Handler for xml downloads
	 */
	@ResourceMapping(value = "exportxml")
	public void exportDataXml(ResourceRequest request, ResourceResponse response) {

		// Replicate export logic here from displaytag
		TableModel exportModel = (TableModel) request.getPortletSession()
				.getAttribute(request.getParameter("tableId"), PortletSession.APPLICATION_SCOPE);
		
		XmlView exportXml = new XmlView();
		exportXml.setParameters(exportModel, true, true, false);
		
		
		try {
			response.setContentType(TEXT_XML);
			response.setProperty("Content-Disposition", "attachment;filename=\"" + "export.xml" + "\"");
			Writer writer = response.getWriter();
			exportXml.doExport(writer);

		} catch (IOException e) {
			e.printStackTrace();
		} catch (JspException e) {
			e.printStackTrace();
		}
	}
	
	
}


3. In the view component(my case a jsp), I add these links manually. Do not enable the export option on the tag.

<span>Export options : </span>
	<a href="<portlet:resourceURL escapeXml=" false" id="exportcsv">
		<portlet:param name="tableId" value="eachResult"></portlet:param>
	"&gt;CSV</a>
	<a href="<portlet:resourceURL escapeXml=" false" id="exportxls">
		<portlet:param name="tableId" value="eachResult"></portlet:param>
	"&gt;XLS</a>
	<a href="<portlet:resourceURL escapeXml=" false" id="exportxml">
		<portlet:param name="tableId" value="eachResult"></portlet:param>
	"&gt;XML</a>


"eachResult" is the tableid used in like


<display:table id="eachResult">
</display:table>


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

Hope this helps.

Cheers
Rajni Bharara, modificado hace 12 años.

RE: [Resolved]RE: displaytag pagaing & export to excel,csv etc.. not wo

New Member Mensaje: 1 Fecha de incorporación: 7/03/12 Mensajes recientes
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