File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exporting in excel using display tag in struts

 
Mahanth Kumar
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using display tag 1.1.1( http://displaytag.sourceforge.net/11/ )to display data and export data to an excel file in struts 1.2

though i am able to display the table successfully on the jsp page ...the excel file is empty

i have already tried configuring the export filter but that doesnt do a thing.

i have been trying to get this to work for the past 2 days in vain ...what am i missing???

my entire code:


welcome page:-------------------------------------

<%@ page language="java"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<html>
<head>
<title></title>

</head>
<body bgcolor="white">

<a href = "trialDo.do">link to the action</a>



</body>
</html>
---------------------------------------------------------------------------
destination page:---------------------------------------------------------
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ page language="java"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@ page buffer = "16kb" %>

<html>

<body>


</br></br>
<display:table name = "tryForm.tryList" export = "true" id = "currrowobj">
<display:column property="name" title="Name"/>
<display:column property="desig" title = "Designation"/>



</display:table>





</body>



</html>


---------------------------------------------------------------------------
action and bean config in struts-config.xml:-------------------------------

<action-mappings>
<action
path="/trialDo"
type="trialpack.TrialAction"
name="tryForm"
scope="request"
>
<forward name = "success" path = "/pages/trialdispjsp.jsp"/>
</action>
</action-mappings>

<form-beans>

<form-bean
name="tryForm"
type="trialpack.TryForm"/>
</form-beans>

--------------------------------------------------------------------------

Action class:-------------------------------------------------------------

package trialpack;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class TrialAction extends Action{

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

TryForm tF = (TryForm)form;
List<TrialObj> tlist = new ArrayList<TrialObj>();
for(int i = 0; i < 5 ; i++){

TrialObj tB = new TrialObj();
String name = "Name"+i;
System.out.println(name);
tB.setName(name);
tB.setDesig(name);
tlist.add(tB);

}
tF.setTryList(tlist);

for(int i = 0; i < 5; i++)
{
System.out.println("hello");
System.out.println(tF.getTryList().get(i).getName());
}




return (mapping.findForward("success"));
}


}
---------------------------------------------------------------------------
formbean:------------------------------------------------------------------

package trialpack;

import java.util.List;

import org.apache.struts.action.ActionForm;

public class TryForm extends ActionForm{

private static final long serialVersionUID = 1L;
private List<TrialObj> tryList;


public List <TrialObj> getTryList() {
return tryList;
}
public void setTryList(List <TrialObj> tryList) {
this.tryList = tryList;
}




}
---------------------------------------------------------------------------

trialobj:------------------------------------------------------------------
package trialpack;

public class TrialObj {


private String name = "";
private String desig = "";


public String getDesig() {
return desig;
}
public void setDesig(String desig) {
this.desig = desig;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}


}


---------------------------------------------------------------------------
export filter config in web.xml:-------------------------------------------

<filter>
<filter-name>ResponseOverrideFilter</filter-name>
<filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>ResponseOverrideFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ResponseOverrideFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>


---------------------------------------------------------------------------
 
Schevus Osborne
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as you make it to your destination JSP and the table is populated correctly, this doesn't sound like a Struts issue at all. Do you have a properties file for your display tag configurations?

- Schevus
 
Mahanth Kumar
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i did try adding a properties file...but that doesnt help either...here is the file
---------------------------------------------------------------------------
#sort.behavior=list
#sort.amount=list
#basic.empty.showtable=true
#basic.msg.empty_list=No results matched your criteria.
#paging.banner.placement=top
#paging.banner.onepage=<span class="pagelinks"></span>
export.types=csv excel xml
export.excel=true
export.csv=true
export.xml=true
export.excel.class=org.displaytag.export.excel.DefaultHssfExportView
# if set, file is downloaded instead of opened in the browser window
export.excel.filename=excel.xls
---------------------------------------------------------------------------

another seemingly bizzare thing i noticed was that the table wont show up on the jsp page if i change the action scope to session from request or even if i remove the attribute altogether
 
Nyanas Kandhan
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a step by step explanation of how to export a file to excel refer this example. Export To Excel Using Display Tag
 
Javier Dussaillant
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I know this is an OLD thread, but I'm wondering if you ever got to solve this problem.

I'm modifying an equally old web application made by someone else, and I'm facing the same problem. The grid displays without problems in html, but when trying to export, it just refreshes the page and truncates at the grid position. No errors or exceptions, and if I debug I can see the collection is populated. Everything "works", except that it just won't download the file.


thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic