aspose file tools*
The moose likes Struts and the fly likes exporting in excel using display tag in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "exporting in excel using display tag in struts" Watch "exporting in excel using display tag in struts" New topic
Author

exporting in excel using display tag in struts

Mahanth Kumar
Greenhorn

Joined: Dec 10, 2007
Posts: 4
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

Joined: Jan 21, 2008
Posts: 7
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

Joined: Dec 10, 2007
Posts: 4
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

Joined: Jan 27, 2009
Posts: 35
For a step by step explanation of how to export a file to excel refer this example. Export To Excel Using Display Tag


regards,
Nyanaskandhan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exporting in excel using display tag in struts
 
Similar Threads
Problem with login page
org.apache.jasper.JasperException: Module 'null' not found.
struts forward link?
adding taglib to web.xml
Struts module problem