You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Glenn Davidson <gb...@yahoo.com> on 2005/06/16 20:32:44 UTC
OT: How do you intergrate a Jasper Report into a MYFaces app?
All,
I am looking at Jasper reports but I am unsure the best way to integrate Jasper Reports into a My Faces Application. Any help would be greatly appreciated. If you are able to help and you come to NYC at any time, the beer is on me!
Thanks
Glenn
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: OT: How do you intergrate a Jasper Report into a MYFaces app?
Posted by Graham Stark <gr...@virtual-worlds.biz>.
Well, I'm sure there are dozens of people on this list better at this
than I am, but I did get this to work so here goes:
In the jsp I have:
<af:commandButton
rendered="#{model.annualReportAvailable}"
actionListener="#{model.makeAccountsReport}"
returnListener="#{model.makeAccountsReport}"
text="Your annual report is available" />
(this is an Oracle ADF button, but it should be almost the same using
Myfaces).
Model is my model, declared in the usual ways. It contains an
isAnnualReportAvailable method, various things to fill up the report,
and makeAccountsReport method which looks like:
public void makeAccountsReport( ActionEvent event ){
try{
Reporter reporter = new Reporter();
// fill in your report here...
reporter.setStuff(....);
FacesContext context =
FacesContext.getCurrentInstance();
HttpServletResponse response =
(HttpServletResponse)
context.getExternalContext().getResponse();
response.setContentType(
"application/pdf");
response.setHeader(
"Content-disposition",
"attachment;filename=AnnualReport_"+
model.getYear()+".pdf" );
OutputStream out =
response.getOutputStream();
reporter.writeReport( out );
context.responseComplete();
} catch ( Exception e ){
logger.error( "getAccountsReport(): failed to write"+
" pdf to output with exception " + e );
}
}
You can try it here, if you like:
http://www.mazegreenyachts.com
(not quite finished, but getting there). The report should appear on the
main results page every fourth quarter. (Actually, the version here is
using Fop rather than Jasper Reports, but the principle is exactly the
same)
hope this helps
Graham
> Graham,
> This is great but would it be possible to see a bit more? I am
> completely in the dark about how the report is added to the web
> application. What must happen? what does the JSF page code look like?
> I can see how to generate the report but how to I transfer that to the
> client machine? I am afraid I am a bit of a newbie when it comes to
> report generation and printing.
>
> Thanks
>
> Glenn
>
>
> Graham Stark <gr...@virtual-worlds.biz> wrote:
> Glenn,
>
> Don't know if this is any good to you, but here's an excerpt
> from one
> I've just finished:
> ....
> FacesContext context = FacesContext.getCurrentInstance();
> HttpServletResponse response = (HttpServletResponse)
> context.getExternalContext().getResponse();
> response.setContentType( "application/pdf" );
> response.setHeader(
> "Content-disposition",
> "attachment;filename=AnnualReport_"+model.getYear()+".pdf");
>
> OutputStream out = response.getOutputStream();
> reporter.writeReport( out );
> FacesContext.getCurrentInstance().responseComplete();
> ....
>
> where the reporter is a little class that wraps the Jasper
> reports code.
>
> Graham
>
> > All,
> > I am looking at Jasper reports but I am unsure the best way
> to
> > integrate Jasper Reports into a My Faces Application. Any
> help would
> > be greatly appreciated. If you are able to help and you come
> to NYC at
> > any time, the beer is on me!
> >
> > Thanks
> >
> > Glenn
> >
> >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam protection
> around
> > http://mail.yahoo.com
> --
> Graham Stark, Virtual Worlds
> phone: (+044) 01908 618239 mobile: 07952 633185
> Homepage http://www.virtual-worlds.biz/people/graham_s
> Virtual Chancellor http://www.virtual-worlds.biz/vwc
>
>
>
> ______________________________________________________________________
> Discover Yahoo!
> Get on-the-go sports scores, stock quotes, news & more. Check it out!
--
Graham Stark, Virtual Worlds
phone: (+044) 01908 618239 mobile: 07952 633185
Homepage http://www.virtual-worlds.biz/people/graham_s
Virtual Chancellor http://www.virtual-worlds.biz/vwc
RE: OT: How do you intergrate a Jasper Report into a MYFaces app?
Posted by Dani Kenan <da...@netvision.net.il>.
Glen,
Leaving MyFaces out, do you know how to show it using a simple servlet/jsp
application?
If not, could you describe the use case and user interaction you want to use
for generating a sample report?
Dani
_____
From: Glenn Davidson [mailto:gbadavidson@yahoo.com]
Sent: Thursday, June 16, 2005 10:38 PM
To: MyFaces Discussion
Subject: Re: OT: How do you intergrate a Jasper Report into a MYFaces app?
Graham,
This is great but would it be possible to see a bit more? I am completely in
the dark about how the report is added to the web application. What must
happen? what does the JSF page code look like? I can see how to generate the
report but how to I transfer that to the client machine? I am afraid I am a
bit of a newbie when it comes to report generation and printing.
Thanks
Glenn
Graham Stark <gr...@virtual-worlds.biz> wrote:
Glenn,
Don't know if this is any good to you, but here's an excerpt from one
I've just finished:
....
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)
context.getExternalContext().getResponse();
response.setContentType( "application/pdf" );
response.setHeader(
"Content-disposition",
"attachment;filename=AnnualReport_"+model.getYear()+".pdf");
OutputStream out = response.getOutputStream();
reporter.writeReport( out );
FacesContext.getCurrentInstance().responseComplete();
....
where the reporter is a little class that wraps the Jasper reports code.
Graham
> All,
> I am looking at Jasper reports but I am unsure the best way to
> integrate Jasper Reports into a My Faces Application. Any help would
> be greatly appreciated. If you are able to help and you come to NYC at
> any time, the beer is on me!
>
> Thanks
>
> Glenn
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
--
Graham Stark, Virtual Worlds
phone: (+044) 01908 618239 mobile: 07952 633185
Homepage http://www.virtual-worlds.biz/people/graham_s
Virtual Chancellor http://www.virtual-worlds.biz/vwc
_____
Discover Yahoo!
Get on-the-go sports scores, stock quotes, news & more. Check
<http://us.rd.yahoo.com/evt=32661/*http:/discover.yahoo.com/mobile.html> it
out!
Re: OT: How do you intergrate a Jasper Report into a MYFaces app?
Posted by Glenn Davidson <gb...@yahoo.com>.
Graham,
This is great but would it be possible to see a bit more? I am completely in the dark about how the report is added to the web application. What must happen? what does the JSF page code look like? I can see how to generate the report but how to I transfer that to the client machine? I am afraid I am a bit of a newbie when it comes to report generation and printing.
Thanks
Glenn
Graham Stark <gr...@virtual-worlds.biz> wrote:
Glenn,
Don't know if this is any good to you, but here's an excerpt from one
I've just finished:
....
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)
context.getExternalContext().getResponse();
response.setContentType( "application/pdf" );
response.setHeader(
"Content-disposition",
"attachment;filename=AnnualReport_"+model.getYear()+".pdf");
OutputStream out = response.getOutputStream();
reporter.writeReport( out );
FacesContext.getCurrentInstance().responseComplete();
....
where the reporter is a little class that wraps the Jasper reports code.
Graham
> All,
> I am looking at Jasper reports but I am unsure the best way to
> integrate Jasper Reports into a My Faces Application. Any help would
> be greatly appreciated. If you are able to help and you come to NYC at
> any time, the beer is on me!
>
> Thanks
>
> Glenn
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
--
Graham Stark, Virtual Worlds
phone: (+044) 01908 618239 mobile: 07952 633185
Homepage http://www.virtual-worlds.biz/people/graham_s
Virtual Chancellor http://www.virtual-worlds.biz/vwc
---------------------------------
Discover Yahoo!
Get on-the-go sports scores, stock quotes, news & more. Check it out!
Re: OT: How do you intergrate a Jasper Report into a MYFaces app?
Posted by Graham Stark <gr...@virtual-worlds.biz>.
Glenn,
Don't know if this is any good to you, but here's an excerpt from one
I've just finished:
....
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)
context.getExternalContext().getResponse();
response.setContentType( "application/pdf" );
response.setHeader(
"Content-disposition",
"attachment;filename=AnnualReport_"+model.getYear()+".pdf");
OutputStream out = response.getOutputStream();
reporter.writeReport( out );
FacesContext.getCurrentInstance().responseComplete();
....
where the reporter is a little class that wraps the Jasper reports code.
Graham
> All,
> I am looking at Jasper reports but I am unsure the best way to
> integrate Jasper Reports into a My Faces Application. Any help would
> be greatly appreciated. If you are able to help and you come to NYC at
> any time, the beer is on me!
>
> Thanks
>
> Glenn
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
--
Graham Stark, Virtual Worlds
phone: (+044) 01908 618239 mobile: 07952 633185
Homepage http://www.virtual-worlds.biz/people/graham_s
Virtual Chancellor http://www.virtual-worlds.biz/vwc