You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ChristopherAngel <ch...@googlemail.com> on 2007/04/10 13:50:14 UTC
Struts 2 Jasper Reports Plugin
I have the following package defined in my struts.xml file:
<package name="jasper" extends="jasperreports-default">
<action name="getReport" class="com.action.ReportAction"
method="generateReport">
<result name="success" type="jasper">
<param name="location">reports/report.jasper</param>
<param name="dataSource">dataSource</param>
</result>
</action>
</package>
the generateReport method is called as expected except despite ReportAction
implementing ServletRequestAware the setServletRequest method is never
called.
How can I get access to the HttpServletRequest object from within the
generateReport method?
--
View this message in context: http://www.nabble.com/Struts-2-Jasper-Reports-Plugin-tf3552530.html#a9918148
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 Jasper Reports Plugin
Posted by sattanari <ka...@gmail.com>.
hi
iam sending one example have a look at this
package com.kogent.action;
import com.opensymphony.xwork2.*;
import net.sf.jasperreports.engine.JasperCompileManager;
import java.text.*;
import java.sql.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
public class ReportsAction extends ActionSupport implements
ServletRequestAware, ServletResponseAware
{
private HttpServletRequest request=null;
private HttpServletResponse response=null;
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
JasperReport jasperReport;
JasperPrint jasperPrint;
JasperDesign jasperDesign;
private List<MonthlyStatement> myList=null;
private List<Dummy> dummyList=null;
private String fromdate;
private String todate;
private String reporttype;
private String accountnumber;
public String getAccountnumber() {
return accountnumber;
}
public void setAccountnumber(String accountnumber) {
this.accountnumber = accountnumber;
}
public String getFromdate() {
return fromdate;
}
public void setFromdate(String fromdate) {
this.fromdate = fromdate;
}
public String getReporttype() {
return reporttype;
}
public void setReporttype(String reporttype) {
this.reporttype = reporttype;
}
public String getTodate() {
return todate;
}
public void setTodate(String todate) {
this.todate = todate;
}
public void setServletRequest(HttpServletRequest request)
{
this.request=request;
}
public void setServletResponse(HttpServletResponse response)
{
this.response=response;
}
public String execute()
{
System.out.println("************ Execute Method is Called
***************");
myList = new ArrayList<MonthlyStatement>();
dummyList = new ArrayList<Dummy>();
Dummy dummy = new Dummy();
dummy.setTxreference("some Referece");
dummy.setTxdetails("detauks");
dummy.setTxamount("200");
dummyList.add(dummy);
String dir = request.getRealPath("/");
try
{
/*Class.forName("com.mysql.jdbc.Driver");
con= DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root","123456");
stmt= con.createStatement();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date fdate = sdf.parse(fromdate);
java.util.Date tdate = sdf.parse(todate);
java.sql.Timestamp fromDate = new java.sql.Timestamp(fdate.getTime());
java.sql.Timestamp toDate = new java.sql.Timestamp(tdate.getTime());
String query = "select * from monthlystatement where date between
'"+fromDate+"' AND '"+toDate+"' ";
rs = stmt.executeQuery(query);
while(rs.next())
{
MonthlyStatement monthStatement = new MonthlyStatement();
//monthStatement.setDate(date)
monthStatement.setTransactiondetails(rs.getString("transactiondetails"));
monthStatement.setTransactionreference(rs.getString("transactionreference"));
monthStatement.setTransactionamount(rs.getString("amount"));
// monthStatement.setDate(rs.getTimestamp("date"));
myList.add(monthStatement);
System.out.println(" SIZE OF LIST IS========>" + myList.size());
}
*/
JasperCompileManager.compileReportToFile(dir+"/jasper/our_jasper_template.jrxml",dir+"/jasper/our_compiled_template.jasper");
/* load JasperDesign from XML and compile it into JasperReport
jasperDesign =
JRXmlLoader.load(dir+"/jasperReports/our_jasper_template.jrxml");
jasperReport = JasperCompileManager.compileReport(jasperDesign);
fill JasperPrint using fillReport() method
jasperPrint =
JasperFillManager.fillReport(jasperReport,parameters,con);
JasperExportManager.exportReportToPdfFile(jasperPrint,
dir+"/jasperReports/output.jasper");
response.setContentType("application/pdf");
*/
}
catch(Exception e)
{
System.out.println(e);
}
return SUCCESS;
}
public List<MonthlyStatement> getStatement()
{
System.out.println(" Returning Size Is ==============>" + myList.size());
return myList;
}
public List<Dummy> getDummyList()
{
return dummyList;
}
}
--
View this message in context: http://www.nabble.com/Struts-2-Jasper-Reports-Plugin-tp9918148p18903505.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: R: Array of Bean and optionsCollection (up)
Posted by Laurie Harper <la...@holoweb.net>.
Marcello Savino wrote:
>> At first sight, u miss the name of the collection in "
>> <html:optionsCollection property="aBean" value="code"
>> label="descr"/>"
> Do you mean i have to specify the attribute name="aBean"instead of
> property="aBean" ?
You only need to specify the 'name' attribute if you want to specify a
bean other than the form bean. Assuming the data you want to reference
is in the form bean, as in your case, you only need to specify the
'property' attribute.
>> second u forgot the dot in myBeanCode , it's myBean.code , Struts will
> do myBean.getCode().
> myBeanCode is only a name for the current bean in the select tag
The 'property' attribute on the select tag should name a property in
your form bean. That tells Struts where to store/retrieve the associated
value (current selection).
>> third : your form property "aBean" is an array & u use a select ( which
> a single property)
> Do you mean i have to specify the attribute name="aBean"instead of
> property="aBean" ?
You need *two* properties on your form bean: one to hold the list of
options, which you have (the 'aBean' property); and one to hold the
value that's actually selected. The html:select tag's 'property'
attribute should reference the second one:
public class MyForm extends ActionForm {
private myBean[] arrayOfMyBean;
private String selectedValue;
public myBean[] getABean() {return arrayOfMyBean;}
public String getSelectedValue() {return selectedValue;}
public String setSelectedValue(String val) {
selectedValue = val;}
}
<html:select property="selectedValue" >
<html:optionsCollection property="aBean"
value="code" label="descr"/>
</html:select>
L.
> Thanks for your attention
>
>
>
> 2007/4/11, Marcello Savino <Ma...@aldebra.com>:
>> Please excuse me but i try again ... (hope will never die)
>>
>> Hi all, i've the following problem using the tag
>> <html:optionsCollection, the jsp give the following error:
>> org.apache.jasper.JasperException: No bean specified
>>
>> Let's say this is my code (actionForm, jsp, bean class)
>>
>> public class MyForm extends ActionForm {
>> private myBean[] arrayOfMyBean;
>> public void reset(ActionMapping mapping, HttpServletRequest
>> request){
>> arrayOfMyBean=someClass.getMyBeanArray();
>> request.setAttribute("aBean", arrayOfMyBean);
>> super.reset( mapping, request);
>> }
>> public myBean[] getABean(return arrayOfMyBean); // i forgot
>> this on my previous post, not on my code!
>> }
>> ______________________________________________________
>>
>> The jsp:
>>
>> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html:xhtml
>
>> /> <html:html locale="true"> <body> <html:form action="/MyAction">
>> <html:select property="myBeanCode" >
>> <html:optionsCollection property="aBean" value="code"
>> label="descr"/>
>> </html:select>
>> </html:form>
>> </body>
>> </html:html>
>> ________________________________________________________
>>
>> myBean Class:
>>
>> public class myBean implements java.io.Serializable{
>> private Integer code;
>> private String descr;
>>
>> public Integer getCode(){return code;}
>> public String getDescr(){return descr;}
>>
>> public void setCode(Integer val){ code=val;}
>> public void setDescr(String val){ descr=val;} }
>>
>> _________________________________________________________
>>
>>
>> Could anyone help me?
>> Any help will be greatly appreciated.
>> Thanks in advance
>> Marcello
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
R: Array of Bean and optionsCollection (up)
Posted by Marcello Savino <Ma...@aldebra.com>.
>At first sight, u miss the name of the collection in "
><html:optionsCollection property="aBean" value="code"
>label="descr"/>"
Do you mean i have to specify the attribute name="aBean"instead of
property="aBean" ?
>second u forgot the dot in myBeanCode , it's myBean.code , Struts will
do myBean.getCode().
myBeanCode is only a name for the current bean in the select tag
>third : your form property "aBean" is an array & u use a select ( which
a single property)
Do you mean i have to specify the attribute name="aBean"instead of
property="aBean" ?
Thanks for your attention
2007/4/11, Marcello Savino <Ma...@aldebra.com>:
>
> Please excuse me but i try again ... (hope will never die)
>
> Hi all, i've the following problem using the tag
> <html:optionsCollection, the jsp give the following error:
> org.apache.jasper.JasperException: No bean specified
>
> Let's say this is my code (actionForm, jsp, bean class)
>
> public class MyForm extends ActionForm {
> private myBean[] arrayOfMyBean;
> public void reset(ActionMapping mapping, HttpServletRequest
> request){
> arrayOfMyBean=someClass.getMyBeanArray();
> request.setAttribute("aBean", arrayOfMyBean);
> super.reset( mapping, request);
> }
> public myBean[] getABean(return arrayOfMyBean); // i forgot
> this on my previous post, not on my code!
> }
> ______________________________________________________
>
> The jsp:
>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html:xhtml
> /> <html:html locale="true"> <body> <html:form action="/MyAction">
> <html:select property="myBeanCode" >
> <html:optionsCollection property="aBean" value="code"
> label="descr"/>
> </html:select>
> </html:form>
> </body>
> </html:html>
> ________________________________________________________
>
> myBean Class:
>
> public class myBean implements java.io.Serializable{
> private Integer code;
> private String descr;
>
> public Integer getCode(){return code;}
> public String getDescr(){return descr;}
>
> public void setCode(Integer val){ code=val;}
> public void setDescr(String val){ descr=val;} }
>
> _________________________________________________________
>
>
> Could anyone help me?
> Any help will be greatly appreciated.
> Thanks in advance
> Marcello
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Array of Bean and optionsCollection (up)
Posted by Romu <ro...@gmail.com>.
At first sight, u miss the name of the collection in "
<html:optionsCollection property="aBean" value="code"
label="descr"/>"
second u forgot the dot in myBeanCode , it's myBean.code , Struts will do
myBean.getCode().
third : your form property "aBean" is an array & u use a select ( which a
single property)
not clear but i could have understood wrong .
Good luck
2007/4/11, Marcello Savino <Ma...@aldebra.com>:
>
> Please excuse me but i try again ... (hope will never die)
>
> Hi all, i've the following problem using the tag
> <html:optionsCollection, the jsp give the following error:
> org.apache.jasper.JasperException: No bean specified
>
> Let's say this is my code (actionForm, jsp, bean class)
>
> public class MyForm extends ActionForm {
> private myBean[] arrayOfMyBean;
> public void reset(ActionMapping mapping, HttpServletRequest
> request){
> arrayOfMyBean=someClass.getMyBeanArray();
> request.setAttribute("aBean", arrayOfMyBean);
> super.reset( mapping, request);
> }
> public myBean[] getABean(return arrayOfMyBean); // i forgot this
> on my previous post, not on my code!
> }
> ______________________________________________________
>
> The jsp:
>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html:xhtml
> /> <html:html locale="true"> <body> <html:form action="/MyAction">
> <html:select property="myBeanCode" >
> <html:optionsCollection property="aBean" value="code"
> label="descr"/>
> </html:select>
> </html:form>
> </body>
> </html:html>
> ________________________________________________________
>
> myBean Class:
>
> public class myBean implements java.io.Serializable{
> private Integer code;
> private String descr;
>
> public Integer getCode(){return code;}
> public String getDescr(){return descr;}
>
> public void setCode(Integer val){ code=val;}
> public void setDescr(String val){ descr=val;} }
>
> _________________________________________________________
>
>
> Could anyone help me?
> Any help will be greatly appreciated.
> Thanks in advance
> Marcello
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Array of Bean and optionsCollection (up)
Posted by Marcello Savino <Ma...@aldebra.com>.
Please excuse me but i try again ... (hope will never die)
Hi all, i've the following problem using the tag
<html:optionsCollection, the jsp give the following error:
org.apache.jasper.JasperException: No bean specified
Let's say this is my code (actionForm, jsp, bean class)
public class MyForm extends ActionForm {
private myBean[] arrayOfMyBean;
public void reset(ActionMapping mapping, HttpServletRequest
request){
arrayOfMyBean=someClass.getMyBeanArray();
request.setAttribute("aBean", arrayOfMyBean);
super.reset( mapping, request);
}
public myBean[] getABean(return arrayOfMyBean); // i forgot this
on my previous post, not on my code!
}
______________________________________________________
The jsp:
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html:xhtml
/> <html:html locale="true"> <body> <html:form action="/MyAction">
<html:select property="myBeanCode" >
<html:optionsCollection property="aBean" value="code"
label="descr"/>
</html:select>
</html:form>
</body>
</html:html>
________________________________________________________
myBean Class:
public class myBean implements java.io.Serializable{
private Integer code;
private String descr;
public Integer getCode(){return code;}
public String getDescr(){return descr;}
public void setCode(Integer val){ code=val;}
public void setDescr(String val){ descr=val;} }
_________________________________________________________
Could anyone help me?
Any help will be greatly appreciated.
Thanks in advance
Marcello
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Array of Bean and optionsCollection (revisted)
Posted by Marcello Savino <Ma...@aldebra.com>.
Hi all, i've the following problem using the tag <html:optionsCollection
Let's say this is my code (actionForm, jsp, bean class)
public class MyForm extends ActionForm {
private myBean[] arrayOfMyBean;
public void reset(ActionMapping mapping, HttpServletRequest
request){
arrayOfMyBean=someClass.getMyBeanArray();
request.setAttribute("aBean", arrayOfMyBean);
super.reset( mapping, request);
}
public myBean[] getABean(return arrayOfMyBean); // i forgot this
on my previous post, not on my code!
}
______________________________________________________
The jsp:
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:xhtml />
<html:html locale="true">
<body>
<html:form action="/MyAction">
<html:select property="myBeanCode" >
<html:optionsCollection property="aBean" value="code"
label="descr"/>
</html:select>
</html:form>
</body>
</html:html>
________________________________________________________
myBean Class:
public class myBean implements java.io.Serializable{
private Integer code;
private String descr;
public Integer getCode(){return code;}
public String getDescr(){return descr;}
public void setCode(Integer val){ code=val;}
public void setDescr(String val){ descr=val;} }
_________________________________________________________
When i open the jsp i got the following Error:
org.apache.jasper.JasperException: No bean specified
Could anyone help me?
Any help will be greatly appreciated.
Thanks in advance
Marcello
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Aray of Bean and optionsCollection
Posted by Marcello Savino <Ma...@aldebra.com>.
Hi all, i've the following problem using the tag <html:optionsCollection
Let's say this is my code (actionForm, jsp, bean class)
public class MyForm extends ActionForm {
private myBean[] arrayOfMyBean;
public void reset(ActionMapping mapping, HttpServletRequest
request){
arrayOfMyBean=someClass.getMyBeanArray();
request.setAttribute("aBean", arrayOfMyBean);
super.reset( mapping, request);
}
}
______________________________________________________
The jsp:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html:xhtml />
<html:html locale="true">
<body>
<html:form action="/MyAction">
<html:select property="myBeanCode" >
<html:optionsCollection property="aBean" value="code"
label="descr"/>
</html:select>
</html:form>
</body>
</html:html>
________________________________________________________
myBean Class:
public class myBean implements java.io.Serializable{
private Integer code;
private String descr;
public Integer getCode(){return code;}
public String getDescr(){return descr;}
public void setCode(Integer val){ code=val;}
public void setDescr(String val){ descr=val;}
}
_________________________________________________________
When i open the jsp i got the following Error:
org.apache.jasper.JasperException: No bean specified
Could anyone help me?
Any help will be greatly appreciated.
Thanks in advance
Marcello
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 Jasper Reports Plugin
Posted by Patrick J Kobly <pa...@kobly.com>.
You probably want st like:
<package name="jasper" extends="jasperreports-default,struts-default">
The problem is that the servlet request is set by an interceptor
(servlet-config) that is in the default stack defined in
struts-default. The jasperreports-default package does not define any
interceptor stacks, and does not extend any other packages.
PK
ChristopherAngel wrote:
> Apparently using HttpServletRequest request =
> ServletActionContext.getRequest();
>
> So why is the setServletRequest method not called?
>
>
> ChristopherAngel wrote:
>
>> I have the following package defined in my struts.xml file:
>>
>> <package name="jasper" extends="jasperreports-default">
>> <action name="getReport" class="com.action.ReportAction"
>> method="generateReport">
>> <result name="success" type="jasper">
>> <param name="location">reports/report.jasper</param>
>> <param name="dataSource">dataSource</param>
>> </result>
>> </action>
>> </package>
>>
>> the generateReport method is called as expected except despite
>> ReportAction implementing ServletRequestAware the setServletRequest method
>> is never called.
>>
>> How can I get access to the HttpServletRequest object from within the
>> generateReport method?
>>
>>
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 Jasper Reports Plugin
Posted by ChristopherAngel <ch...@googlemail.com>.
Apparently using HttpServletRequest request =
ServletActionContext.getRequest();
So why is the setServletRequest method not called?
ChristopherAngel wrote:
>
> I have the following package defined in my struts.xml file:
>
> <package name="jasper" extends="jasperreports-default">
> <action name="getReport" class="com.action.ReportAction"
> method="generateReport">
> <result name="success" type="jasper">
> <param name="location">reports/report.jasper</param>
> <param name="dataSource">dataSource</param>
> </result>
> </action>
> </package>
>
> the generateReport method is called as expected except despite
> ReportAction implementing ServletRequestAware the setServletRequest method
> is never called.
>
> How can I get access to the HttpServletRequest object from within the
> generateReport method?
>
>
>
--
View this message in context: http://www.nabble.com/Struts-2-Jasper-Reports-Plugin-tf3552530.html#a9918621
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org