Jump to content
Changes to the Jaspersoft community edition download ×

Jasper reports in JSF: life cycle issue


Recommended Posts

By: ht_jw - ht_jw

Jasper reports in JSF: life cycle issue

2006-06-12 08:59

I am creating a Jasper report in JSF action listener.

 

1. The report is downloaded fine the first time.

2. It always loads the current page afterwards no matter what link/button I click.

3. It works fine again the third time.

 

The code is like this:

 

byte[] pdf = createPdfReport();

 

FacesContext faces = javax.faces.context.FacesContext.getCurrentInstance();

HttpServletResponse response = (HttpServletResponse) faces.getExternalContext()

.getResponse();

 

response.setContentType( "application/pdf" );

response.setContentLength( pdf.length );

response.setHeader( "Content-disposition", "attachment; filename="" + createFileName() + """ );

ServletOutputStream out;

try

{

out = response.getOutputStream();

out.write( pdf );

}

catch ( IOException ex )

{

log.error( "Could not output file:" + ex );

}

faces.responseComplete();

return "next_page";

 

What puzzles me is it always loads the current page in #2 and it goes through Restore-view and Render-response phases only for the current page.

 

Anybody has success in creating PDF jasper report in JSF? Could you share it? Any suggestion is appreciated.

Link to comment
Share on other sites

  • 4 years later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Have you found a solution to this problem?  I've been trying to display a .pdf in a web page using JSF and have an issue with a file not found error.  I'm going about it differently, creating, compiling, and exporting the .pdf to a file, then using <h:panelGrid> and <iframe> to display the .pdf.  I cannot, however, get the .pdf to display without manually hitting reload inside the frame.  The report gets created, but no matter what I've tried I cannot get the program to wait long enough for the file to be written before attempting to display (I have a loop that tests whether the file is created and returns a boolean when it is).  Any insight you've gained would be a big help.  Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...