JasperReports 3.5 for Java Developers- P8

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:17

0
76
lượt xem
14
download

JasperReports 3.5 for Java Developers- P8

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Tham khảo tài liệu 'jasperreports 3.5 for java developers- p8', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả

Chủ đề:
Lưu

Nội dung Text: JasperReports 3.5 for Java Developers- P8

  1. Chapter 11 connection = DriverManager.getConnection("jdbc:mysql://localhost: 3306/flightstats?user=user&password=secret"); JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, new HashMap(), connection); connection.close(); servletOutputStream.flush(); servletOutputStream.close(); return mapping.getInputForward(); } } All the action classes must extend the org.apache.struts.action.Action class. Typically, the execute() method is overridden to implement custom logic for servicing a request. As can be seen in this code, the execute() method takes an instance of HttpServletResponse as one of its parameters. This makes it easy to write action classes that generate reports. The technique illustrated in the preceding example is not much different from what we have seen in various earlier examples throughout the book. In most examples, we used standard Java servlets to generate web reports, implementing the report logic in the servlet's doGet() method. As both the HttpServlet.doGet() and Action.execute() methods take an instance of HttpServletResponse as one of their parameters, the technique to generate a report from an action class is virtually identical to the technique used when employing a servlet. Let us take a look at the JSP that will invoke the GenerateReportAction.execute() method. Generate Report Click on the button to generate the report. [ 339 ]
  2. Integrating JasperReports with Other Frameworks This JSP will generate a very simple HTML form with a Submit button as its only input field. Next, let us take a look at the form bean for this JSP. package net.ensode.jasperbook.struts; import org.apache.struts.action.ActionForm; public class GenerateReportForm extends ActionForm { } As the HTML form generated by the preceding JSP has no input fields other than a Submit button, its corresponding form bean has no fields. We still need to write it because, when writing Struts applications, each JSP must have a corresponding form bean. To wire the action class, the form bean, and the JSP together, we need to create a struts-config.xml file and deploy it in the WEB-INF directory of the application's war file. [ 340 ]
  3. Chapter 11 The tag defines the GenerateReportForm class as a form bean and assigns the logical name generateReportForm to it. The tag maps the GenerateReportAction action class to the /generate_report path. It also specifies that the GenerateReportForm form bean will be associated with this action. Finally, it links the generate_report.jsp JSP file through the input attribute. Like all server-side Java web applications, Struts applications must contain a web. xml file in the WEB-INF directory inside the application's war file. Struts JasperReports Application action org.apache.struts.action.ActionServlet config /WEB-INF/struts-config.xml debug 2 detail 2 2 action *.do This web.xml file simply defines the Struts ActionServlet to process all the URLs ending in .do. The Struts ActionServlet calls the appropriate JSP and action class behind the scenes for the appropriate URL. [ 341 ]
  4. Integrating JasperReports with Other Frameworks Following the standard procedure for deploying web applications, we create a WAR file with the preceding files and required dependencies, deploy it to a servlet container, and point the browser to the corresponding URL. We should then see a web page similar to the following: Clicking on the Submit button generates the report, exports it to PDF, and displays it in the browser. [ 342 ]
  5. Chapter 11 Summary The chapter started with integrating JasperReports with Hibernate by writing embedded report queries in the HQL. JasperReports with HQL queries is similar to reports containing SQL queries except that the language attribute of the element must be set to hql. Next, we saw how to integrate JasperReports with the JPA. As with Hibernate, JPA integration requires that the language attribute of the element be modified. For JPA, the value of this attribute must be set to ejbql. Following our discussion of JPA, we saw how to integrate JasperReports with the Spring framework by taking advantage of Spring's built-in support for JasperReports integration. The chapter also dealt with JSF and JasperReports integration and illustrated how to write backing beans that fill a report and display it in the browser. Finally, the chapter illustrated the integration of JasperReports with Struts by explaining how to write action classes that fill a report and display it in the browser. [ 343 ]
  6. Index Symbols subelement 220 subelement 221 element 50, 135 subelement 221 element 219 subelement 221 element 219 element subelement 221 about 190 subelement 222 attributes 190 subelement 222 customizerClass 190 subelements 220 evaluationGroup 191 subelement 222 evaluationTime 191 subelement isShowLegend 191 about 221 element 52 attributes 221 subelement class attribute 221 about 220 name attribute 221 attributes 220 element 219 headerPosition attribute 220 element height attribute 220 about 192 name attribute 220 attributes 192 totalPosition attribute 220 element, attributes element 51 incrementGroup 193 element 220 incrementType 193 subelement resetGroup 193 about 220 resetType 193 attributes 220 178 columnTotalGroup attribute 220 element 51 height attribute 220 element 107 rowTotalGroup attribute 221 element 48, 62 width attribute 221 element 49 subelement element about 221 about 49, 148 attributes 221 attributes 148 isDataPreSorted attribute 221 isReprintHeaderOnEachPage 148 element isResetPageNumber 148 about 219, 220 isStartNewColumn 148 subelement 220 isStartNewPage 148
  7. element subelement about 188 221 attributes 188 element element, attributes about 194 evaluationGroup 188 attributes 194 evaluationTime 188 element, attributes hAlign 188 backcolor 194 IsLazy 189 backgroundAlpha 194 isUsingCache 189 foregroundAlpha 194 onErrorType 190 orientation 194 vAlign 189 element 46 element 47 element 48, 62, 73 root elements 50 about 159 52 attributes 159 51 , attributes 51, 52 backcolor 161 48 forecolor 161 49 height 161 49 isPrintInFirstWholeBand 161 47 isPrintRepeatedValues 161 53 isPrintWhenDetailOverFlows 161 54, 55 isRemoveLineWhenBlank 161 52 key 161 50 mode 161 48 positionType 161 46 printWhenGroupChanges 161 48 stretchType 161 48 width 161 47 x 161 47 y 161 53 subelement 47 about 222 50 attributes 222 49 178 element 53 element 219 subelement subelement about 221 about 222 attributes 221 attributes 222 calculation attribute 241 headerPosition attribute 222 class attribute 221 name attribute 222 name attribute 221 totalPosition attribute 222 element 54 width attribute 222 element 52 element 48 element 50 element element 48 about 47, 122 178 attributes 122 [ 346 ]
  8. element, attributes Apache ANT 26 backcolor 123 Apache Commons fontName 123 about 13, 24 fontSize 123 Commons Digester library 25 forecolor 123 optional libraries 26 hAlign 123 Apache Commons BeanUtils 26 isBold 123 Apache Commons Collections 25 isItalic 123 Apache Commons Logging 25 isStrikeThrough 123 Apache POI 13 isUnderline 123 linespacing 123 B vAlign 123 element 47, 48 bar charts JRXML element about 198 about 178 creating 198-201 subelements 178 binary report template JRXML element, subelements compiled report template, previewing 178 34, 35 178 creating 33 178 JRXML template, compiling 33 element 53 JRXML template, compiling through element 47 ANT 36, 38 element bookmarkLevel attribute 238 linespacing attribute 126 bookmarks rotation attribute 126 about 237 textAlignment attribute 126 generating 237, 238 element 62 built-in report parameters, empty data- element 50 sources element about 88 about 49, 150 is_ignore_pagination 88 attributes 150 report_connection 88 element, attributes report_data_source 88 calculation 152 report_locale 88 class 152 report_max_count 88 incrementerFactoryClass 152 report_parameters_map 88 incrementGroup 152 report_resource_bundle 88 incrementType 152 report_scriptlet 88 name 152 report_virtualizer 89 resetGroup 152 built-in report variables resetType 152 about 156 subelement 222 column_count 156 column_number 156 A nameofgroup_count 156 page_count 156 anchors page_number 156 about 230, 231 report_count 156 adding, to reports 230, 231 [ 347 ]
  9. C CSV datasources about 111 chart items net.sf.jasperreports.engine.data.JRCsvData- turning, into hyperlinks 232-234 Source, using 111 charts CSV format adding, to report 190 reports, exporting to 258-260 area chart 204 custom datasources bar charts 198 about 113 bubble chart 204 custom JRDataSource implementation, candlestick chart 204 using 115-117 element 190 custom JRDataSource implementation, customizing 192 writing 114, 115 datasets 192 custom JRDataSource implementation gantt chart 204 employing 115-117 high low chart 204 writing 114, 115 line chart 204 meter chart 204 D multiple axis chart 204 pie charts 195 database report, iReport plotting 194 creating 278-282 scatter plot chart 204 generated report, tweaking 283 stacked area chart 204 database reports stacked bar chart 204 database reporting, through datasource thermometer chart 204 72- 78 times series chart 204 generating 59 types 204 methods, comparing 78 XY area chart 204 report, generating 63-66 XY bar chart 204 report query, modifying through report XY line chart 204 parameters 67-70 XY line charts 201 SQL queries, embedding into report class library dependencies template 60-62 about 13 datasource Apache Commons 13 about 57 Apache POI 13 CSV datasources 111 JAXP 13 custom datasources 113 JFreeChart 13 Java objects, as datasources 94 common element properties map datasources 89 about 167 XML datasources 106 setting 167, 169 data transfer object. See DTO Commons Digester library displayReport() method 104 about 25 Document Type Definition (DTD) 256 Apache Commons BeanUtils 26 DTO 95 Apache Commons Collections 25 Apache Commons Logging 25 E compileReportToFile() method 33 crosstabs 216-220 empty datasources CSV 258 built-in report parameters 88 report parameters, assigning values to 87 [ 348 ]
  10. evaluationGroup attribute 188 RemoteAnchor 232 evaluationTime attribute 188 RemotePage 232 Excel format reports, exporting to 252, 253 I F images adding, to report 186, 187 filling 16, 63 example 187 fillReportToFile() method incrementGroup attribute 193 about 39 incrementType attribute 193 parameters 39 iReport versions 39 about 271 for hyperLinkTarget attribute database report, creating 278-282 about 235 database report, generating quickly 278 values 235 downloading 272-274 features 304 G installing 274 report, creating from scratch 284-292 generateReport() method 104 reports, modifying 292 geometrical shapes setting up 275-277 adding, to reports 181 IsLazy attribute 189 ellipses, adding to report 185, 186 isUsingCache attribute 189 lines, adding to report 182, 183 iText library 27 rectangles, adding to report 183, 184 getFieldValue() method 115, 214 J getName() method 115 getParameterValue() method 214 JasperCompileManager.compileReport getVariableValue() method 214 ToFile() method getWriter() method 267 about 33 GPL 271 parameters 33 jasper file 16 H JasperFillManager class 73 JasperFillManager.fillReport() method 268 hAlign attribute 188 JasperForge Hibernate about 16 about 308 official online forums 17 JasperReports, integrating with 308-319 JasperPrint file 16 HTML format JasperReports reports, exporting to 254, 255 built-in report variables 156 HTML reports common element properties, setting 167, directing, to browser 264-269 169 hyperlinks about 8 about 230, 231 anchors, adding 230, 231 adding, to reports 230, 231 chart items, turning into LocalAnchor 232 hyperlinks 232-235 LocalPage 232 charts, adding 190 none 232 class library dependencies 13 Reference 232 crosstabs 216 [ 349 ]
  11. downloading 20 JasperReports, download links downloading, from SourceForge 20 applet.jar 21 download links 21 .jar 22 ellipses, adding 185 javaflow.jar 22 environment, setting up 23 project.tar.gz 22 features 9 project.zip 22 geometrical shapes, adding 181 JasperReports, features history 7 about 9 hyperlinks, adding 230, 231 exporting capabilities 11 images, adding 186 flexible report layout 9 integrating, with Hibernate 308-319 multiple datasources 10 integrating, with JPA 319-326 report data, displaying ways 10 integrating, with JSF 333-337 report data, supplying ways 10 integrating, with Spring 327-332 subreports 11 integrating, with Struts 338-342 watermarks 11 large reports, handling 239, 241 JasperSoft 8 lines, adding 182 Java Development Kit. See JDK official online forums 16 Java Development Tools. See JDT rectangles, adding 183 Java objects report localization 207 using as datasources 94 requisites 9 Java objects, as datasources scriplets 210 JRBeanCollectionDataSource, using 99 subdatasets 222 net.sf.jasperreports.engine.JRBeanArrayDa- support 16 taSource, using 97-99 workflow 14 report template, modifying 95-97 repeated values, hiding 170-173 JAXP 13 report background, setting 134 JDBC driver report elements, laying out 159 about 27 report-wide layout properties, controlling RDBMS 27 120, 148 JDK 9 subreports 173 JDT 9 text fields, stretching to accommodate data JDT compiler 26 156-159 JExcelApi 28 text properties, setting 121 JFreeChart 13 JasperReports-3.1.4 directory JFreeChart library 28 build 23 JPA build.xml 23 about 319 changes.txt 23 JasperReports, integrating with 319-326 demo 23 JRAbstractScriptlet class 210 dist 23 JRDefaultScriptlet class 210 docs 23 JRMapArrayDataSource class 91 lib 23 JROdtExporter class 250 license.txt 23 JRResultSetDataSource class 73 pom.xml 23 JRXML file readme.txt 23 elements 30 src 23 30 JasperReports class library 24 30 [ 350 ]
  12. 30 JDBC driver 27 JRXML files 15 JDT compiler 26 JRXML report template JExcelApi 28 creating 29, 30 JFreeChart library 28 elements 46 Organization for the Advancement of XML report template, previewing 31, 32 Structured Information Standards. JSF See OASIS about 333 ORM Tool 307 JasperReports, integrating with 333-337 P L PDF format Lesser GNU Public Library 8 reports, exporting to 245, 246 pie charts M about 195 creating 195-197 map datasources creating, in 2D 195 about 89 creating, in 3D 195 net.sf.jasperreports.engine.data.JRMapAr- plain text format rayDataSource class, executing 89- 91 reports, exporting to 261, 263 net.sf.jasperreports.engine.data.JRMapCol- POJOs 10, 94 lectionDataSource, executing 92, 93 public void afterColumnInit() method 211 markup language, used for text styling public void afterDetailEval() method 211 HTML 130 public void afterGroupInit(String RTF 131 groupName) method 211 MDX 118 public void afterPageInit() method 211 moveFirst() method 113 public void afterReportInit() method 211 public void beforeColumnInit() method 211 N public void beforeDetailEval() method 211 public void beforeGroupInit(String net.sf.jasperreports.engine.data.JRMapAr- groupName) method 211 rayDataSource class 91 public void beforePageInit() method 211 next() method 115 public void beforeReportInit() method 211 O R OASIS 250 RDBMS ODT 250 Firebird 27 ODT format HSQLDB 27 reports, exporting to 250, 251 JavaDB/Derby 27 official online forums 16 MySQL 27 OLAP 118 Oracle 27 onErrorType attribute 190 PostgreSQL 27 OpenDocument Text. See ODT SQL Server 27 optional libraries, JasperReports Sybase 27 about 26 repeated values Apache ANT 26 hiding 170-173 iText 27 [ 351 ]
  13. report Rich Text Format. See RTF multiple columns, adding 140-148 RTF 248 report columns, final notes 144, 148 RTF format creating 29 reports, exporting to 248, 249 displaying, on web browser 43, 44 exporting 244 S exporting overview 244 exporting, to CSV format 258-260 scriplets exporting, to Excel format 252, 253 about 210 exporting, to HTML format 254, 255 example 211 exporting, to ODT format 250, 251 features 211, 213, 214 exporting, to PDF format 245, 246 setFieldNames() method 115 exporting, to plain text format 261 setParameter() method 244 exporting, to RTF format 248, 249 setUseFirstRowAsHeader() method 113 exporting, to XML format 256-258 setVisible() method 104 generating 38 Spring viewing 41, 43 about 327 report background JasperReports, integrating with 327-332 setting 134, 135 Struts report data about 338 grouping 144-148 JasperReports, integrating with 338-342 report elements subdatasets laying out 159 about 222, 227 position, setting 162-167 bar chart, generating 227-229 size, setting 162 example 222-225 report expressions subreports method, calling 136 about 173, 178 PDF report, generating 138, 139 JRXML template 173-175 report, iReport charts, adding 299-304 T creating, from scratch 284-292 TableModels datasources images, adding 292, 293 report, generating 104, 106 modifying 292 text fields multiple columns, adding 294-296 stretching, to accommodate data 156-159 report data, grouping 296-298 text properties report text, styling setting 121 HTML, used 130 styles 121 markup language, used 127, 129 styles, reusing through style RTF, used 131, 133 templates 124, 125 report variables styles, using 121 about 148 text style, setting for individual report duplicate expression, eliminating 148-150 elements 126 report, modifying 152-155 text style, setting for individual report report-wide layout properties element 126 controlling 120, 148 resetGroup attribute 193 resetType attribute 193 [ 352 ]
  14. U URI 111 V vAlign attribute 189 Value object. See VO VO 95 W workflow, JasperReports 14 X XML datasources about 106 element, adding in element 107, 109 net.sf.jasperreports.engine.data.JRXmlData- Source, using 109, 111 XML document 107 XML format reports, exporting to 256-258 XML report templates 14 XY line charts about 201, 203 creating 201, 203 Y y Align, element 189 y, element 161 [ 353 ]
  15. Thank you for buying JasperReports 3.5 for Java developers Packt Open Source Project Royalties When we sell a book written on an Open Source project, we pay a royalty directly to that project. Therefore by purchasing JasperReports 3.5 for Java developers, Packt will have given some of the money received to the JasperReports project. In the long term, we see ourselves and you—customers and readers of our books—as part of the Open Source ecosystem, providing sustainable revenue for the projects we publish on. Our aim at Packt is to establish publishing royalties as an essential part of the service and support a business model that sustains Open Source. If you're working with an Open Source project that you would like us to publish on, and subsequently pay royalties to, please get in touch with us. Writing for Packt We welcome all inquiries from people who are interested in authoring. Book proposals should be sent to author@packtpub.com. If your book idea is still at an early stage and you would like to discuss it first before writing a formal book proposal, contact us; one of our commissioning editors will get in touch with you. We're not just looking for published authors; if you have strong technical skills but no writing experience, our experienced editors can help you develop a writing career, or simply get some additional reward for your expertise. About Packt Publishing Packt, pronounced 'packed', published its first book "Mastering phpMyAdmin for Effective MySQL Management" in April 2004 and subsequently continued to specialize in publishing highly focused books on specific technologies and solutions. Our books and publications share the experiences of your fellow IT professionals in adapting and customizing today's systems, applications, and frameworks. Our solution-based books give you the knowledge and power to customize the software and technologies you're using to get the job done. Packt books are more specific and less general than the IT books you have seen in the past. Our unique business model allows us to bring you more focused information, giving you more of what you need to know, and less of what you don't. Packt is a modern, yet unique publishing company, which focuses on producing quality, cutting-edge books for communities of developers, administrators, and newbies alike. For more information, please visit our website: www.PacktPub.com.
  16. Pentaho Reporting 3.5 for Java Developers ISBN: 978-1-847193-19-3 Paperback: 300 pages Create advanced reports, including cross tabs, sub- reports, and charts that connect to practically any data source using open source Pentaho Reporting. 1. Create great-looking enterprise reports in PDF, Excel, and HTML with Pentaho's Open Source Reporting Suite, and integrate report generation into your existing Java application with minimal hassle 2. Use data source options to develop advanced graphs, graphics, cross tabs, and sub-reports Learning SQL Server 2008 Reporting Services ISBN: 978-1-847196-18-7 Paperback: 512 pages A step-by-step guide to getting the most of Microsoft SQL Server Reporting Services 2008 1. Everything you need to create and deliver data-rich reports with SQL Server 2008 Reporting Services as quickly as possible 2. Packed with hands-on-examples to learn and improve your skills 3. Connect and report from databases, spreadsheets, XML Data, and more Please check www.PacktPub.com for information on our titles
Đồng bộ tài khoản