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 <[EMAIL PROTECTED]> 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