Jump to content
We've recently updated our Privacy Statement, available here ×

szaboaz

Members
  • Posts

    29
  • Joined

  • Last visited

szaboaz's Achievements

Apprentice

Apprentice (3/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Collaborator Rare

Recent Badges

0

Reputation

  1. I know I can a) use iReport for viewing the report, but I need a printable version, and b) the template viewer is not enough: e.g. somehow I'd like to display the "print when" expressions along the fields they applied to. To put it another way: I'd like to achieve something like Microsoft Word's commenting feature. Or yet another way: our client doesn't want to learn, how to use iReport. They gave us samples, we did it in JasperReports, which works great. And now they want to have better understanding, what is happening inside the reports. E.g. they'd like to see which fields' appearance are conditional, and what is the condition. What database table-field is displayed in the fields. Yet, they don't want to use iReport for this, they need a pdf which they can print, and work out with pencil and paper, whether they'd like to ask further changes and what those changes would be. (And a generated report with example data doesn't enough either, since conditional fields have a behaviour according to their condition of course, and we cannot generate every possible version.) And to be honest, they have another reason (which they don't actually know): some nice workarounds were applied during the creation of the reports, which would make their lives a little bit difficult if they'd like to get an good understanding of the reports by opening them in iReport: the textFields have 1px height, and they are in many dummy groups, since we have long long reports, and the dummy groups have to be placed to the page's bottom, if they can fit there. I wrote a short description about it in a previous thread: http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=42979#43473 Possible solutions would be: 1) Create an "analysis version" of all the reports. Manually. Sounds like much work, and if anything changes in the report, it has to be done in the analysis version too... 2) Put extra content into the very same fields, and make them appear if an "ANALYSIS" parameter is true. Sounds like much work either... And all the conditional expressions shouldn't apply. Does it make any sense to anyone? I was wondering if I could actually PUT extra fields and switch off conditional expressions automatically, by working on the jrxml, or rather through the API. But putting extra fields between another fields, and changing the 1px height fields to e.g. 19 px, and position them one above the other programmatically doesn't sound like fun either. I've read the new feature of 3.1.0 about "generic component support" with "custom made visual components". I wonder if you see some kind of "field comment" component a good candidate for using this feature. Thanks, Arpad
  2. What do you mean by "where". Of course, to the place where other band elements are. Here's an average-ish jrxml (with no actual content): Code:<?xml version="1.0" encoding="UTF-8" ?> <!-- Created with iReport - A designer for JasperReports --> <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperReport name="Untitled_report_1" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="NoPages" isTitleNewPage="false" isSummaryNewPage="false"> <property name="ireport.scriptlethandling" value="2" /> <property name="ireport.encoding" value="UTF-8" /> <import value="java.util.*" /> <import value="net.sf.jasperreports.engine.*" /> <import value="net.sf.jasperreports.engine.data.*" /> <background> <band height="0" isSplitAllowed="true" > </band> </background> <title> <band height="50" isSplitAllowed="true" > </band> </title> <pageHeader> <band height="50" isSplitAllowed="true" > </band> </pageHeader> <columnHeader> <band height="30" isSplitAllowed="true" > </band> </columnHeader> <detail> <band height="100" isSplitAllowed="true" > </band> </detail> <columnFooter> <band height="30" isSplitAllowed="true" > </band> </columnFooter> <pageFooter> <band height="50" isSplitAllowed="true" > </band> </pageFooter> <lastPageFooter> <band height="50" isSplitAllowed="true" > </band> </lastPageFooter> <summary> <band height="50" isSplitAllowed="true" > </band> </summary> </jasperReport> As you can see, there's a <background></background> element there. So according to the advices in the previous message, you have to set the background's height to the maximum available value (which is the page size minus top and bottom margins). Then you put your border (that is a rectangle element) into the band (with the appropriate size - in this case it is also the maximum available, I guess). Is it clearer? Arpad
  3. In index.jsp lines 35-43 and lines 52-57 are for the usage of datasources in relation of a subreport. I used datasources for both the master (masterreport_ds.jrxml) and the subreport (subreport_ds.jrxml). Subreport's datasource is put into the parameters of the master report, and this very same parameter is set as Data Source Expression in the subreport element of masterreport_ds.jrxml. Lines 59-64 (now commented out) demonstrates the usage of subreports without datasources (using only the Connection object). This time, masterreport_sql.jrxml and subreport_sql.jrxml contain their own sql query string. If you watch the two result pdfs carefully, you can notice one important thing about datasources: result_with_connection.pdf contains three records from master report, and every record has its own subreport section containing several records from the subreport. However, result_with_datasources.pdf contains the three records from the master report also, but only the first record has its own subreport section, the second and third one doesn't. This is because the subreport datasource is consumed first time. If you want to give a datasource to a subreport, you have to be careful, to assure that your subreport will appear only once. Best regards, Arpad [file name=subreport_with_datasource.zip size=16476] Post edited by: szaboaz, at: 2008/07/16 09:30 Post edited by: szaboaz, at: 2008/07/16 09:32
  4. Please see my answer in the other thread you started: "Multiple datasource in one report - 2008/07/14 17:44" http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=view&id=43537&catid=8 Arpad
  5. Yeah, subreports are your friends, just like lshannon suggested in the other thread. Arpad
  6. Try this: to the Print When Expression, write Code:new Boolean(true)and Code:[code]new Boolean(false) and try it. Does the image appear/disappear? If yes, then the parameter handling must be the problem. Does your parameter have any default value set (which takes over, if you mis-spelled it in your code)? You can also write out your parameter's value into a TextField, just to be sure, that it is what you think it is. Good luck, Arpad
  7. I thought it wouldn't be useless if I write a small follow-up on this. As far as workarounds work well, the tip solved the problem basically. The design time height of my dummy groups became 20-30 pixels, and it's a rare case, when they contain so much optional elements, which would result in a smaller height in the generated report. However, the 1px height TextFields also brought another problem to the surface: the vertical alignment of the elements. Previously, I had 17 pixels height StaticTexts and TextFields, with about 11 pixels Font size. They were attached vertically to each others, to form lines, and the difference between line heights and font sizes gave a nice couple pixels of space between them. Now that I had 1pixels TextFields set to stretch with overflow, this space has gone. I first tried to set the TextFields linespacing to 1-1-2, or Double, and it made a difference, but I had TextFields, which stretched into more than one lines, and the space between those lines were also 1-1-2/double. Next, I put empty space between the TextFields. This was OK, until I saw, that if I have an optional line, which is not displayed actually, the empty space around it remained, and "pushed away" the ones around it. The final solution was that I put one pixel height TextFields, with a space in the String expression. (Later I changed the space to a dummy character,and set the foreground color to white, because I wasn't sure if the space is working every time.) Then, I applied the print-when expressions to them accordingly with the optional text fields near them. It's quite a big work. These spaceholder TextFields are useful for the following reason: they take only one pixel of my precious desing time height, and their font size can be set to different values, which results in easily configurable "line spacing". To further facilitate this configurableness, I made them wide enough to reach well into the margins. This way I can select all of them with one mouse movement, and set the font size to a different value. I set their background color to different values according to their font size, and I only need to switch the transparent property to true or false, to make the colors displayed or hidden in the generated report. Attached image shows how it looks like in 800% (and shrinked down to 50%, so that forum accept it). Best regards, Arpad size=375]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/spaceholdertextfields.png Post edited by: szaboaz, at: 2008/07/12 11:17
  8. szaboaz

    Blank Pdf

    For sure. The idea behind subreports is that there is a changing data element in every record of the masterreport's data source, and a subreport usually depends on this data (takes it as a parameter, and gets its value from the query's result). This is the most typical usage of subreports. Then, a masterreport can also pass a non-changing value to the subreport, if it is required. So the masterreport has to get this value from somewhere. And where should it get from? Of course from a parameter. So yes, if you want to give a parameter value to a subreport, you have to "inject" it into the masterreport, which forwards it to the subreport to the subreport's own parameter - whether the masterreport actually use it or not. Best regards, Arpad ps. All the things I said before is said "AFAIK", I don't consider myself an authentic source ;-). If I'm wrong, please correct me. Thanks.
  9. szaboaz

    Blank Pdf

    I was curious, how much the difference can be between the two methods (starting with .jrxml, or starting with .jasper). In my case, these were the times, when I made them run five times: .jasper: 1953 1859 1843 1937 1969 .jrxml: 3250 3328 3296 3406 3344 Convincing, isn't it? You can do the same by putting these two lines to your code: Code: long start = System.currentTimeMillis(); System.err.println("Filling time : " + (System.currentTimeMillis() - start)); Best regards, Arpad Post edited by: szaboaz, at: 2008/07/12 08:11 Post edited by: szaboaz, at: 2008/07/12 08:13
  10. szaboaz

    Blank Pdf

    Using .jasper files and not .jrxml makes the code faster, since it doesn't need to do the jrxml->jasper transformation each and every time your report runs. If your report runs thousands and thousands of times, it can cause significant decrease in performance. However, if your code needs to be executed rather rarely, BUT your reports change often, and you have to deploy them again and again, it might be reasonable to use .jrxml files in the code, since you don't need to compile them into .jasper files before you deploy them. Code: package subreportjasperrunner; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; /** * * @author szaboaz */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"«»); Connection connection; try { connection = DriverManager.getConnection("jdbc:mysql://localhost/bank", "root", "password"«»); JasperReport subreport; JasperReport masterreport; try { subreport = JasperCompileManager.compileReport("subreport.jrxml"«»); masterreport = JasperCompileManager.compileReport("masterreport.jrxml"«»); Map parameters = new HashMap(); parameters.put("SubreportParameter", subreport); //It can be done more than one way: //I choose to follow runReportToPdfFile method's code //in JasperRunManager.java (in fact, I copied it from there). //But I use a fix string for output filename) //If a previous file exists with the same filename, it will be overwritten. JasperPrint jasperPrint = JasperFillManager.fillReport(masterreport, parameters, connection); JasperExportManager.exportReportToPdfFile(jasperPrint, "masterreport.pdf"«»); //Another approach: //this time, I didn't use JasperRunManager.runReportToPdfFile, //since it cannot use a JasperReport as parameter. //runReportToPdf, however, could take a JasperReport object //as parameter, and it returns a byte array: //byte[] pdf = JasperRunManager.runReportToPdf(masterreport, parameters, connection); //you can do whatever you want to do with your byte array //e.g. write it into a file (tricky part to decide, what to do with //the filenames, should it overwrite or not, if it already exists //or apply some logic to save the file with some differences in the //name all the time... } catch (JRException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } catch (SQLException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } catch (ClassNotFoundException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } }
  11. szaboaz

    Blank Pdf

    Here you are. This time I created a masterreport.jrxml and a subreport.jrxml, and used a MySQL connection to actually make them run, and they did! The reports demonstrate essentially the same "feature" as your files modified previously by me: masterreport has a "SubreportParameter" parameter of type JasperReport, this is used in the subreport element of the masterreport as Subreport Expression. It's your turn now to apply it to your reports (and your database connection, of course) :) Good Luck, Arpad [file name=notaservletthistime.zip size=3968]
  12. szaboaz

    Blank Pdf

    I've modified your jrxml files, and wrote a servlet, which should run it, if you set the database connection properly, and place the jasper files to a place where they can be get by the ServletContext. What did I modify: I added a parameter named SubreportParam, of type net.sf.jasperreports.engine.JasperReport to the master report. I set this parameter as Subreport Expression of the subreport element (and made sure, that it's type, the Subreport Expression Class, is set to net.sf.jasperreports.engine.JasperReport). In the Java code I create a net.sf.jasperreports.engine.JasperReport object instance from the subreport, and put it into the parameters Map. And that's all, it should fly (hope, hope). Good Luck, Arpad [file name=rbojja.zip size=26274] Post edited by: szaboaz, at: 2008/07/11 14:06
  13. What is the reason of giving a JRDataSource to the master report in your java code, instead of giving the Connection itself to it? (Especially becouse your master report contains an SQL query, which is absolutely unnecessary, and doesn't do anything.) Now your master report has a JRDataSource, and forwards this very same datasource to the subreport (through $P{REPORT_CONNECTION}). And the subreport also contains an SQL query, which should run on the JRDatasource?!? HTH, Arpad ps. I had no problem opening the two jasper files from the attached help.zip file. Oh, and another remark, while I'm at it. The subreport's page width is 535. However, it is intended to fit into the detail band of your master report, which is narrower (by the size of the two side margins), isn't it? Let me recommend to set your subreport's page width to 535-30-30=475, and position your subreport element to the 0th pixel of the detail band, and set its width to 475 accordingly. Post edited by: szaboaz, at: 2008/07/11 08:00 Post edited by: szaboaz, at: 2008/07/11 08:01
  14. You can find lots of demo code (including subreports) in demo/samples directory of JasperReports' "project" release. (You can find it at the sourceforge download place, the one with "project" in its name.) Best regards, Arpad Post edited by: szaboaz, at: 2008/07/11 06:44 Post edited by: szaboaz, at: 2008/07/11 06:46
  15. szaboaz

    Help Plz

    What if you use TextField (not StaticText) for the long text? You can set its vertical size to a small value, eg. 17 pixels, and set its "Stretch with overflow" value to true. Doing so, you will have the necessary space for placing other things to the page. This will not save you from lines going to the second page, if the middle part of your report grows big vertically, though. (But how can you put an elephant into a mouse-hole?) HTH, Arpad ps. use meaningful subject lines to your posts, it helps people to find out, if they can help you or not.
×
×
  • Create New...