jasperreports 3.6 development cookbook

456 414 0
jasperreports 3.6 development cookbook

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info JasperReports 3.6 Development Cookbook Over 50 recipes to create next-generation reports using JasperReports Bilal Siddiqui BIRMINGHAM - MUMBAI www.it-ebooks.info JasperReports 3.6 Development Cookbook Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: June 2010 Production Reference: 1220610 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849510-76-9 www.packtpub.com Cover Image by Vinayak Chittar (vinayak.chittar@gmail.com) www.it-ebooks.info Credits Author Bilal Siddiqui Reviewers Nadeem Ghafoor Chaudhry Sagara Gunathunga Lloyd H. Meinholz Bhavani P. Polimetla Acquisition Editor Dilip Venkatesh Development Editor Mayuri Kokate Technical Editors Ishita Dhabalia Vinodhan Nair Indexer Monica Ajmera Mehta Editorial Team Leader Gagandeep Singh Project Team Leader Priya Mukherji Project Coordinator Zainab Bagasrawala Proofreader Sandra Hopper Graphics Geetanjali Sawant Production Coordinators Aparna Bhagat Arvindkumar Gupta Cover Work Aparna Bhagat www.it-ebooks.info About the Author Bilal Siddiqui is an Electronics Engineer, an XML consultant, and the founder of XML4Java. com, a company focused on simplifying e-business. After graduating in 1995 with a degree in electronics engineering from the University of Engineering and Technology, Lahore, he began designing software solutions for industrial control systems. Later, he turned to XML and used his programming experience in C++ to build web- and WAP-based XML processing tools, server-side parsing solutions, and service applications. Bilal is a technology evangelist and a frequently published technical author. Bilal has been focusing exclusively on Java and XML-based open source tools and solutions since 2006. He has extensively used popular open source products such as JasperReports, ADempiere, Openbravo, and Eclipse. Bilal is a strong advocate of open source tools and is engaged not only in designing solutions based on open source tools but also collaborating with local universities in Lahore to train software and IT personnel in using open source technologies. Special thanks to my wife's patience, which was often put to the test while I was working on this book. I'm also thankful for the support of Rainer Maier—my friend and business partner, who was quite convinced that I should just work on this book and sleep instead of working on our mutual projects. Finally, I am also thankful to my colleagues, Tariq and Zia, for their ideas to make this book more interesting and useful. www.it-ebooks.info About the Reviewers Nadeem Ghafoor Chaudhry received his B.S. and M.S. in Computer Science from the University of Massachusetts, Lowell, U.S.A. He worked in the software industry in the U.S. for about four years. Then he switched to academia in Pakistan and taught both undergraduate and graduate courses at different institutes of higher learning in Pakistan. Currently, he is engaged as Assistant Professor in the department of Computer Science of COMSATS Institute of Information Technology, Lahore, Pakistan. COMSATS Institute of Information Technology (CIIT) is a renowned institute for higher learning in Pakistan. Currently, the CIIT is offering 47 different degree programs divided into 20 undergraduate and 27 graduate programs in the elds of Information and Communication Technology, Management Sciences, Electrical Engineering, Chemical Engineering, Mathematics, Physics, Bio-sciences, Development Studies, Environmental Science, Meteorology, and Architecture and Design. The present student strength is around 20,000 with faculty corpus of more than 1,600. The CIIT has already produced approximately 10,000 graduates. Sagara Gunathunga holds a special degree in Computer Science (B.Sc.) from the University of Peradeniya, Sri Lanka and a degree in Information Technology (BIT) from the University of Colombo, Sri Lanka. He is an Apache Axis PMC member, an Apache committer for several projects that include Apache Web Service and Apache Woden. His research interest focuses on SOA, web services, distributed systems, and modularity systems. He also has a sound industry experience in J2EE-related technologies, including ORM tools, dependency injection frameworks, and reporting. Currently, he is playing a Tech-Lead role in a U.S based software services company named Aeturnum Inc. Sagara also maintains his blog at http://ssagara.blogspot.com/, and you can get in touch with him at sagaragu@gmail.com. All my thanks go to my mother for supporting me. www.it-ebooks.info Lloyd H. Meinholz works as an IT professional in the Washington D.C. area. He has more than 20 years of experience in developing software in a variety of programming languages and production environments. Lloyd has focused on Java, Linux, and other open source technologies for the past 12 years. He has been employed by start-up companies as well as Fortune 500 companies and worked in both the public and private sectors. Lloyd has found JasperReports and iReport to be a great reporting solution for many of his employers. Bhavani P. Polimetla has been learning and working in the IT Industry since 1990. He graduated as a Bachelor of Computer Science and Master of Computer Applications from Andhra University, India. He worked on standalone Swing applications to Grid computing and N-tire architecture. He has worked with the world's top clients including three from Fortune 50 companies. At present, he is working as an independent Java consultant in Atlanta, Georgia, U.S.A. To demonstrate his skills, he completed 25+ certications in the spectrum of J2EE, database, and project management subjects. He also achieved many awards for many of his projects. He reads and writes poetry in his free time. More information is available at his website www.polimetla.com. www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Creating Static and Dynamic Titles and Headers 7 Introduction 7 Downloading, installing, and running JasperReports and iReport 8 Creating your rst "Hello World" report 10 Creating and sizing the title for your report 15 Using dynamic titles that can change during report processing 20 Inserting a company logo in the title of your report 25 Adding a simple header to your report 28 Setting margins for your report and aligning the report header relative to report margins 34 Chapter 2: Working with the Body and Footer of your Report 41 Introduction 41 Displaying a eld along with its label in the body of your report and handling null values 43 Creating a simple table of records along with labels for each column 51 Inserting a heading for a group of records 59 Using parameters to lter records during report processing 68 Implementing groups within groups — a nested hierarchy 73 Adding a simple footer to your report 81 Displaying general information or summary at the end of your report 90 Chapter 3: Enhancing the Look and Feel of your Report 99 Introduction 99 Deploying and reusing styles in your report 100 Setting background color for data 114 Using HTML tags and bullet lists 123 www.it-ebooks.info ii Table of Contents Expanding a eld vertically to accommodate large text 135 Applying formatting pattern to the value of a data eld 140 Using background images and watermarks in your report 146 Chapter 4: Working with a Variety of Data Sources 151 Introduction 151 Creating a report from relational data 152 Connecting to an XML datasource 158 Creating a report from XML data using XPath 162 Using multiple relational databases to generate a report 171 Creating a report from model beans of Java applications 184 Chapter 5: Multi-page Reports 195 Introduction 195 Building a cover page for your multi-page report 196 Creating a simple, one-page TOC for your report 201 Applying a style to your simple TOC 210 Resetting page numbering with the start of a particular record 218 Implementing complex multi-dimensional page numbering 228 Showing multiple types of data in the same report 239 Managing pagination of multiple types of data in a report 250 Chapter 6: Multi-column Reports 261 Introduction 261 Dividing the body of a report into multiple columns 261 Displaying groups of data in separate columns 266 Displaying data as name-value pairs in multiple columns 270 Filling your report horizontally in multiple columns 276 Using subreports to design a multi-column report 283 Chapter 7: Summary Report, Crosstabs, and Graphs 297 Introduction 297 Designing a simple summary report 297 Designing a multi-level summary report 303 Designing a crosstab—a table with dynamic rows and columns 315 Displaying data trends as a graph in your report 321 Embedding a bar graph inside a tabular view 331 www.it-ebooks.info iii Table of Contents Chapter 8: Java Wrappers for your JasperReports 343 Introduction 343 Creating a Java wrapper for your report 344 Compiling and viewing your report in a Java Swing application 351 Printing the hardcopy of your report using a Java Swing application 357 Creating an Excel report from a Java Swing application 361 Creating a JasperReport on the y in a Java web application 366 Chapter 9: Using Mathematical and Logical Expressions This chapter is not present in the book but is available as a free download from: http://www.packtpub.com/sites/default/files/downloads/0769os-chapter- 9.zip Index 375 www.it-ebooks.info [...]... products are used in this JasperReports 3.6 Development Cookbook: • JasperReports version 3.6. 0 • iReport version 3.6. 0 • PostgreSQL version 8.4 • Apache Tomcat version 6.0.16 • Java Development Kit (JDK) version 1.6.0_12 Who this book is for This book is for Java developers who want to use JasperReports to create user-friendly business reports It is for those who may be familiar with JasperReports but want... into advanced JasperReports activities  www.it-ebooks.info Preface If you know how to use Microsoft Word, you can also learn how to design business reports using iReport by following the recipes of this cookbook Although the primary audiences of this cookbook are report designers, Java and XML developers will find this book useful in understanding how Jasper's XML code works and how to wrap JasperReports. .. View all files button, and a list of all available versions of iReport will appear I used version 3.6. 0 of iReport, which is the latest at the time of writing these recipes Therefore, expand iReport -3.6. 0, by clicking on it It will show all the files related to iReport -3.6. 0 Download the file named iReport-nb -3.6. 0-windowsinstaller.exe This is an executable file 3 Double-click the Windows executable file... which a report is generated Downloading, installing, and running JasperReports and iReport iReport is a powerful visual tool for JasperReports to graphically design reports It is much easier to generate JASPER code using the graphical features of iReport as compared to writing the JASPER code by hand In order to create reports using JasperReports, you will only need to download iReport from the iReport... related to JasperReports with step-by-step instructions on how to solve them The author's experience in creating reports enables him to share over 50 recipes to develop crystal-clear business reports using the capabilities of JasperReports and the amazing features provided by its visual report designer tool: iReport Create and enhance your business reports using the various functionalities of JasperReports. .. the Newest Files section and older versions in the All Files section of the download page Note that I have used iReport version 3.6. 0 in this cookbook iReport versions dated before 2008 are referred to as iReport classic, which might behave differently from the recipes of this cookbook Creating your first "Hello World" report This recipe is a quick starter for someone who is using iReport for the first... which shows what your "Hello World" report will actually look like: How it works JasperReports has defined its own XML-based markup language called JasperReports XML, or JRXML for short JRXML code contains all the information that is required to specify everything about your report Therefore, designing a report using JasperReports means you have to perform the following steps: 1 Write JRXML code manually... This $P is not SQL syntax This $P will be internally processed by the JasperReports engine, which resolves it to the CustomerName parameter before executing the query This way, the SQL query becomes part of your JRXML code and the JasperReports engine will process and execute this query to fetch the customer name from your database JasperReports will also copy the name of the customer into the CustomerName... are set in bold: XML tags > JasperReports XML tags >  www.it-ebooks.info Preface Any command-line input... Introduction This chapter is about the titles and headers of your reports Imagine you are looking for a particular recipe in a cookbook Perhaps the quickest way of doing this is to go through the table of contents, which is just a list of the titles of all the recipes contained in this cookbook So it is important that each title says what the recipe teaches Similarly, the title of your report will help identify . http://www. packtpub.com/sites/default/files/downloads/0 769 os- chapter-9.zip What you need for this book The following software products are used in this JasperReports 3. 6 Development Cookbook: JasperReports version 3. 6. 0 iReport version 3. 6. 0. www.it-ebooks.info JasperReports 3. 6 Development Cookbook Over 50 recipes to create next-generation reports using JasperReports Bilal Siddiqui BIRMINGHAM - MUMBAI www.it-ebooks.info JasperReports 3. 6 Development. 8: Java Wrappers for your JasperReports 34 3 Introduction 34 3 Creating a Java wrapper for your report 34 4 Compiling and viewing your report in a Java Swing application 35 1 Printing the hardcopy

Ngày đăng: 05/05/2014, 11:35

Từ khóa liên quan

Mục lục

  • Cover

  • Copyright

  • Credits

  • About the Author

  • About the Reviewers

  • Table of Contents

  • Preface

  • Chapter 1: Creating Static and Dynamic Titles and Headers

    • Introduction

    • Downloading, installing, and running JasperReports and iReport

    • Creating your first "Hello World" report

    • Creating and sizing the title for your report

    • Using dynamic titles that can change during report processing

    • Inserting a company logo in the title of your report

    • Adding a simple header to your report

    • Setting margins for your report and aligning the report header relative to report margins

    • Chapter 2: Working with the Body and Footer of your Report

      • Introduction

      • Displaying a field along with its label in the body of your report and handling null values

      • Creating a simple table of records along with labels for each column

      • Inserting a heading for a group of records

      • Using parameters to filter records during report processing

Tài liệu cùng người dùng

Tài liệu liên quan