Wednesday Jan 31, 2007

New Tutorial on Using JasperReports in a Visual Web Application

We just published a new Visual Web Pack tutorial, Generating Reports and PDFs From a Web Application that shows how use JasperReports to generate HTML and PDF reports from a data source. JasperReports is a reporting tool that outputs reports in HTML, PDF, XLS, CSV, and XML formats. This tutorial provides code, which you can copy to any project's application bean, that fills a report with the same query result that you use to populate the JavaServer Faces components on a page. The tutorial also shows how to modify the build script to compile the JasperReport templates.

Thanks to Craig Conover and Marina Sum who forged the trail with their tutorial on using JasperReports with the NetBeans IDE, and to Craig McClanahan who made sure my sample code followed the "best practices".

Geertjan just blogged on a JasperReports Visual Designer for the NetBeans IDE. I look forward to exploring this designer and finding out how this designer integrates with Visual Web applications.

Tuesday Jan 30, 2007

Missing Image Bug

I just finished writing a NetBeans Visual Web Pack version of the JasperReports tutorial Generating Reports and PDFs From a Web Application. The NetBeans version should appear on the portal sometime today.

While working on this tutorial, I came across a bug that prevented the company logo from appearing in the HTML output when the application is deployed to version 9 of the Sun Java System Application Server. The bug happens when you request binary data through the FacesServlet, and the fix is in for version 9.1. Ryan and Craig were the engineers who figured out why the problem was happening. They both pointed out to me that the following statement in my code sample, which sets a relative url, is not recommended:

  exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image="); 

The above statement results in following HTML:

  http://localhost:8080/TravelReport/faces/image?image=img_0_0_0

By using the relative URL, I was needlessly incurring, for a non-JavaServer Faces entity, the extra overhead that is associated with a JavaServer Faces request. It is better to serve up the image directly, instead of going through the JavaServer Faces lifecycle.

I am pushing out a new version of the Java Studio Creator tutorial today, which shows the correct way to pass the url (which happens to work with Sun Java Application Server 9):

   exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,
     request.getContextPath() + "/image?image="); 

While we are talking about server bugs, a customer wrote to me that they were getting a java.lang.NullPointerException from the javax.faces.component.UIComponentBase class's getRenderer method whenever they use the Table component in web applications deployed to JBoss. This is a known bug, and is documented in the Release Notes. What is happening is that when you create a Visual Web project, the classpath on the container is checked. If the IDE finds a MyFaces implementation, it gives the MyFaces implementation precedence over the JavaServer Faces Reference Implementation libraries. To prevent this problem from happening, delete or move the JBOSS_HOME/server/default/deploy/jbossweb-tomcat55.sar/jsf-lib directory before you create the Visual Web Pack project for that container. This forces the the IDE to bundle the JSF Reference Implementation with the project.

To go back to using the MyFaces run time for running non-Visual Web Pack based applications, follow these steps:

  1. In the Projects window, right-click the Libraries node and choose Add Library.
  2. In the Add Library dialog box, select the desired MyFaces binaries.
  3. Click Add Library.
  4. Make sure the JSF-RI libraries are not deployed.
  5. Modify web.xml to include the following:
  6. <listener>
      <listener-class>
        org.apache.myfaces.webapp.StartupServletContextListener
      </listener-class>
    </listener>
    

Monday Jan 08, 2007

JasperReports Tutorial: Missing Record Bug

A few customers have pointed out a bug in the Generating Reports and PDFs From a Web Application tutorial. I have to admit that I am somewhat embarrased that I never noticed that the first record is missing from the reports.

I am trying to get the fix pushed out this week. In the meantime, for those who are using code from the tutorial, you should know that you need to either call beforeFirst() or execute() on the rowset before passing the rowset to the JRResultSetDataSource constructor.

Tuesday Nov 21, 2006

Using the JasperReports Framework in Visual Web Applications to Generate PDF and HTML Reports

We just posted the http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/reports.html tutorial to the Sun Java Studio Creator Tutorials web site. This tutorial works for the Visual Web Pack with the following changes.

  • Throughout
    • The source is in src/java instead of just src.
  • Creating a JasperReports Library
    • Step 3: the library type is "Class Libraries"
    • For the Sun Java System Application Server, you must also add the commons-beanutils, commons-collections, and commons-logging jars to the library.
  • Setting Up the JRXML Editing Environment
    • Step 2: Click Advanced Options, then expand Options > IDE Configuration > System > Object Types to get to XML Objects.
  • Creating the Project and Authorizing Access to the JasperReport Classes
    • Create a Visual Web Application and use the BluePrints structure.
    • You do not need to do steps 5 through 10 for the Sun Java System Application Server.
  • Creating the Database Query
    • Also clear the LASTEDUPDATED column from each table.
  • Setting Up the Report Resources
    • To add the second source directory for the JRXML files, switch to the Files window.
    • Right-click the project node, and select New > Folder.
    • Set the folder name to reports.
    • Set the parent folder to src (that is, the "src" directory inside the project) so that this node will be parallel to src/java.
    • Click Finish. Note that the directory is only visible on the files view.
    • Right-click the project name, and select Properties.
    • Click Add Folder, navigate to the src/reports node, and click Open.
    • Change the Label from the default (src/newfolder) to something meaningful, such as JasperReports Definitions and click OK.
    • Switch back to the Projects window, and you will see this new node, with a <default package> node underneath it.
    • Put the JRXML files under the <default package> node (that is, into directory src/reports).
About

divas

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today