• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Icefaces,JasperReport Integration

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All:

I am using Icefaces 1.8.2, Jsf 1.1 and JasperReport 3.5.2.
I click a button and it call "testSearch" and should give return a pdf file. Instead nothing happens. There are no errors and no pdf file.
Any help or hint would be greatly appreciated it

public String testSearch() throws Exception
{
try
{
Connection connection;
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse();
InputStream reportStream = context.getExternalContext().getResourceAsStream("WEB-INF/reports/test_report.jasper");
ServletOutputStream servletOutputStream = response.getOutputStream();
ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String filepath = ctx.getRealPath("/WEB-INF/reports/");
String imagepath = ctx.getRealPath("/WEB-INF/images/test_logo.gif");

HashMap parameterMap = new HashMap();


parameterMap.put("SUBREPORT_DIR", filepath);
parameterMap.put("Test Number", testNumber);
parameterMap.put("Image Path", imagepath);

Properties properties = new Properties();
properties.load(context.getExternalContext().getResourceAsStream("WEB-INF/config.properties"));

String driver = properties.getProperty("jdbc.driver");
String jdbc_url = properties.getProperty("jdbc.url");
String username = properties.getProperty("jdbc.username");
String password = properties.getProperty("jdbc.password");
Class.forName(driver);
connection = DriverManager.getConnection(jdbc_url, username, password);


JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap, connection);

connection.close();

response.setContentType("application/pdf");
servletOutputStream.flush();
servletOutputStream.close();
}
catch(Exception e)
{
log.error("exception message:"+e.getMessage());
}

return "success";
}
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't try and generate non-HTML documents in JSF code. All you will get is pain. Move the report generation functionality to a plain servlet.
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic