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

alestar

Members
  • Posts

    10
  • Joined

  • Last visited

alestar's Achievements

  1. Same issue here. Did someone figure out how to export to Excel using the detail band and passing information through the data source?
  2. Hello, Not sure of how to comment on your answer so I guess I will re-answered again (I did vote for the original answer). Ok, so I am trying to achieve the same that you did in your report. Let's say, I have a category and I want to added sub-categories. In my case I am able to print some information but not the information per each category. How do you actually pass both the Person and Phone information into the table? And later how you organize that information so it shows all the Phones information under a Person, in the table? That is sort of a new topic of how you display/arrange that information, but I would like to know about that too Would you give me more details on that? Thanks in advance
  3. Hello and thanks for the quick answer. I couldn't find how to comment on you answer so I guess I will have to include it in this post. First, you were right about not guaranteeing the whole page layout resizing, by just changing the de page dimensions. However, the formats that I was changing to, were very similar (A4 and LETTER), so the impact on the components and fields size perse, was not that big. Moreover, what I have to do, to actually change every single individual's page of the book format, was loading every single individual page first into a JasperDesing Object holder and next save it , with the modified size into a jasper field, that will be used in the fillup process. Instead of just doing that for the Report Book page itself. Here is the code: private static JasperDesign getPageTemplateDesign(String templatePath) throws JRException{ logger.info("Setting format page desing for Template: " + templatePath); JasperDesign design = JRXmlLoader.load(templatePath); logger.info("Setting Page Dimessions Format to: " + pageFormat); if (JRDriver.pageFormat.equals("A4")) { JRDriver.pageWidth=595; JRDriver.pageHeight=842; JRDriver.columnCount=1; JRDriver.columnWidth=555; JRDriver.columnSpacing=0; JRDriver.leftMargin=20; JRDriver.rightMargin=20; JRDriver.topMargin=20; JRDriver.bottomMargin=20; } else if (JRDriver.pageFormat.equals("LETTER")) { JRDriver.pageWidth=612; JRDriver.pageHeight=792; JRDriver.columnCount=1; JRDriver.columnWidth=517; JRDriver.columnSpacing=0; JRDriver.leftMargin=20; JRDriver.rightMargin=20; JRDriver.topMargin=20; JRDriver.bottomMargin=20; } //Setting twmplate dimesions design.setPageWidth(JRDriver.pageWidth); design.setPageHeight(JRDriver.pageHeight); design.setColumnCount(JRDriver.columnCount); design.setColumnWidth(JRDriver.columnWidth); design.setColumnSpacing(JRDriver.columnSpacing); design.setLeftMargin(JRDriver.leftMargin); design.setRightMargin(JRDriver.rightMargin); design.setTopMargin(JRDriver.topMargin); design.setBottomMargin(JRDriver.bottomMargin); return design; } private static void reformattingPageTemplate(String path) throws JRException{ logger.info("Getting Design Template from: " + path); JasperDesign design= getPageTemplateDesign(path); String destFile=path.replaceAll("jrxml", "jasper"); logger.info("Compiling Re-formated Design Template to: " + destFile); JasperCompileManager.compileReportToFile(design, destFile); } private static void formattingALLPage() throws JRException{ reformattingPageTemplate(reportBookPagesDir + "/FrontCover.jrxml"); reformattingPageTemplate(reportBookPagesDir + "/Copyright.jrxml"); reformattingPageTemplate(reportBookPagesDir + "/TableOfContent.jrxml"); reformattingPageTemplate(reportBookPagesDir + "/Summary.jrxml"); reformattingPageTemplate(reportBookPagesDir + "/Content.jrxml"); reformattingPageTemplate(reportBookPagesDir + "/AppendixWarnings.jrxml"); reformattingPageTemplate(reportBookPagesDir + "/Index.jrxml"); reformattingPageTemplate(reportBookPagesDir + "/BackCover.jrxml"); //reformattingPageTemplate(reportTemplatePath); } Thanks for all the help! ;)
  4. I am bringing this question from this post. I was not sure if I should create a new question since it seems I was already creating a new topic? Apologies upfront for that. So here is my problem: I am trying to dynamically change the format of my report (A book report, with several pages or parts or subreports). What I am doing is loading it first, from an existing template into a JasperDesign Object holder. Then, modifying the size other parameters of the page itself. Later, I will compile and try to print a PDF format report with the compiled file. Ultimately, I want to print a whole book report with different pages and different templates for each individual pages with a format that I can specify. Here is what I have done. I was able to point the main report to the other individual pages formats. So, when I export the report to PDF everything looks good(Like you probably imagine it was not that simple to get there. but now is working). So now I want to parametrize the format (A4, LETTER, etc.) on runtime for every single page of the Book Report. Is this possible? I mean to do this dynamically instead of creating a new static template for each page and format and then creating a maintenance issue? If so which is the way of doing this? Here is my code for retrieving the JasperDesing Object template: private static JasperDesign getTemplateDesign(String templatePath) throws JRException{ JasperDesign design = JRXmlLoader.load(templatePath);logger.info("JASPER DESIGN WIDTH BEFORE: " + design.getPageWidth());logger.info("JASPER DESIGN HEIGTH BEFORE: " + design.getPageHeight()); logger.info("Setting Page Dimessions Format to: " + pageFormat);if (JRDriver.pageFormat.equals("A4")) {JRDriver.pageWidth=595; JRDriver.pageHeight=842;JRDriver.columnCount=1;JRDriver.columnWidth=555;JRDriver.columnSpacing=0;JRDriver.leftMargin=20;JRDriver.rightMargin=20;JRDriver.topMargin=30;JRDriver.bottomMargin=30;}else if (JRDriver.pageFormat.equals("LETTER")) { JRDriver.pageWidth=612; JRDriver.pageHeight=792;JRDriver.columnCount=1;JRDriver.columnWidth=517;JRDriver.columnSpacing=0;JRDriver.leftMargin=20;JRDriver.rightMargin=20;JRDriver.topMargin=30;JRDriver.bottomMargin=30;}//Setting twmplate dimesionsdesign.setPageWidth(JRDriver.pageWidth);design.setPageHeight(JRDriver.pageHeight); design.setColumnCount(JRDriver.columnCount);design.setColumnWidth(JRDriver.columnWidth);design.setColumnSpacing(JRDriver.columnSpacing); design.setLeftMargin(JRDriver.leftMargin);design.setRightMargin(JRDriver.rightMargin);design.setTopMargin(JRDriver.topMargin);design.setBottomMargin(JRDriver.bottomMargin); logger.info("JASPER DESIGN WIDTH AFTER: " + design.getPageWidth());logger.info("JASPER DESIGN HEIGTH AFTER: " + design.getPageHeight()); return design;} Here is my code fragment for generating the PDF report: ... logger.info("Retrieving Design Template..." + reportTemplatePath);JasperDesign design= getTemplateDesign(reportTemplatePath); //jasperReport = JasperCompileManager.compileReport(reportTemplatePath);jasperReport = JasperCompileManager.compileReport(design); logger.info("JASPER REPORT WIDTH BEFORE: " + jasperReport.getPageWidth());logger.info("JASPER REPORT HEIGTH BEFORE: " + jasperReport.getPageHeight()); logger.info("Filling Report...");jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter,new JREmptyDataSource() ); logger.info("JASPER PRINT WIDTH BEFORE: " + jasperPrint.getPageWidth());logger.info("JASPER PRINT HEIGTH BEFORE: " + jasperPrint.getPageHeight()); jasperPrint.setPageWidth(JRDriver.pageWidth);jasperPrint.setPageHeight(JRDriver.pageHeight);logger.info("JASPER PRINT WIDTH AFTER: " + jasperPrint.getPageWidth());logger.info("JASPER PRINT HEIGTH AFTER: " + jasperPrint.getPageHeight()); //Create the file dirFile file = new File(reportOuputPath);file.getParentFile().mkdirs();//file.delete(); logger.info("Writing PDF..." + reportOuputPath);JasperExportManager.exportReportToPdfFile(jasperPrint, reportOuputPath); ... I could include the information for my JRXML static template files. But I don't think that is necessary for now. It can be done if you think otherwise Please help me and thanks in advance
  5. Sorry, it took me a long time to post back. I find a solution after Theodor (Jasper API main author give me some insights) and here is it! So, for the Jasper Report engine to handle multiple data sources passed to the report, you have to take into account 2 essential things: First, for every data source that you want to pass to the Report, you will need to create a new instance. Jasper engine consumes each data source iterating over all the elements in it. When it gets to the next page, there won't be any data, fields or information to read from and fill up the fields on that particular page. Therefore, information won't show up (null) or "blank", depending on the report template configuration. Last, make sure you pass a new JREmptyDataSource() when filling the report and pass the data sources instance as parameters, and later as sub-parameters for each individual page. Like this jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter,new JREmptyDataSource() ); [/code] That way main report, or the wrapping report (the book), does not use any data source of the pages instances (if it does not need it, of course) and each page will get a data source, through the parameters. Ultimately, on runtime, it the page of the book can consume individually each data source without affecting each other. Let me know if this makes any sense? Thanks
  6. Hello and sorry for taking me so long to get back to you. This took me a awhile to figured and thanks to Teodor help himself I was able to solve the problem.
  7. Sorry, it took me a long time to post back. I find a solution after Theodor (Jasper API main author give me some insights) and here is it! So, for the Jasper Report engine to handle multiple data sources passed to the report, you have to take into account 2 essential things: First, for every data source that you want to pass to the Report, you will need to create a new instance. Jasper engine consumes each data source iterating over all the elements in it. When it gets to the next page, there won't be any data, fields or information to read from and fill up the fields on that particular page. Therefore, information won't show up (null) or "blank", depending on the report template configuration. Last, make sure you pass a new JREmptyDataSource() when filling the report and pass the data sources instance as parameters, and later as sub-parameters for each individual page. Like this: jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter,new JREmptyDataSource() );[/code]That way main report, or the wrapping report (the book), does not use any data source of the pages instances (if it does not need it, of course) and each page will get a data source, through the parameters. Ultimately, on runtime, it the page of the book can consume individually each data source without affecting each other. Let me know if this makes any sense? Thanks
  8. Hi, I am trying to add a data source to a "part" of a Report Book. Or I should say passing the information to the fields on that "part" of the ReportBook( or why not, the Main Report). I have come to realize that this is not exactly how things were done with MainReport and Subreport(s). This is a new concept of jasper 6.2.0, so is not exactly the old known subreport and traditional way of doing things(or is it? Do not know..., please if you don't main, explain that too, thanks). I have read a lot of examples out there ( see one here), of how to pass data source through jasper parameters and then, utilize those parameters referenced in <dataSourceExpression>, but it does not seem to be the same way when working with "parts" of a Report Book. I can provide more information, but essentially what I need is to pass that data source to the part, that refer to my other report (or subreport if you will) named Content.jrxml, so the other report can print/render the right information of those fields. This report contains fields and no information is passing to those fields there went I print the Report Book to pdf. those fields are showing as null. However I am able to pass parameters successfully is just with passing the fields values and the data source in general, which I have a problem Does anyone have done or deal with this before or knows of a good example/tutorial that could point me to the solution? Please help me, I don't know what else to do :( Thanks in advance!
  9. Hello, Javier thanks for the quick reply! I am using a map, a JRMapArrayDataSource map object that is been filled up in the GetJasperDataSource() method. The items at that point have information from other processes and that is used to populate the map. So it's not a file or DB connection I will say is a Bean in any case.
  10. Hi, everyone! I have been unsuccessfully trying to pass the information contained on my DataSource into my "Content.jrxml" subreport fields. I am able to print everything ( Front and Back Cover, some extra pages and an empty Table of Content) so far, except the little piece information regarding fields in that specific sub-report. I am even capable of passing parameters from the main report to the subreport and print that information correctly. But when it comes to the fields and information that is being inserted in my DataSource object (JRMapArrayDataSource) and trying to pass that instance to my subreport, is printing "null". Meaning that fields under that sub-report are never initialized, probably... So I try on my main report (Book.jrxml), the following: <detail>[/code]</pre>[/code]<part uuid="6bbe1f1b-154b-4fe1-8c3b-848219b22e5d">[/code]<p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">[/code] <subreportParameter name="REPORT_CONNECTION"><subreportParameterExpression><![CDATA[$P{REPORT_CONNECTION}]]></subreportParameterExpression>[/code] </subreportParameter><subreportParameter name="REPORT_DATA_SOURCE"><subreportParameterExpression><![CDATA[$P{data_source}]]></subreportParameterExpression>[/code] </subreportParameter><subreportExpression><![CDATA[$P{report_book_pages_dir} + "/Content.jasper"]]></subreportExpression>[/code] </p:subreportPart>[/code]</part>[/code]</detail>[/code] These are the fields that I am trying to populate under Content.jrxml: [/code]<field name="group_by" class="java.lang.String"/>[/code] <field name="asset_id" class="java.lang.String"/>[/code] <field name="asset_subject" class="java.lang.String"/>[/code] <field name="feature_group" class="java.lang.String"/> [/code]<field name="component" class="java.lang.String"/> [/code]<field name="sub_component" class="java.lang.String"/> [/code]<field name="reference_maps" class="java.util.List"/>[/code] <field name="release_notes" class="java.lang.String"/>[/code] Also, this is the method that returns my DataSource objects filled up: private JRDataSource GetJasperDataSource() { JRMapArrayDataSource dataSource = null; Map mapDataSource[] = new HashMap[notes.size()]; for(int i = 0; i < notes.size(); i++) { HashMap<String, Object> mappedData = new HashMap<String, Object>(); ReleaseNoteItem item = notes.get(i); if(sortByField.equals("feature_group")) mappedData.put("group_by", item.getFeatureGroup()); else if(sortByField.equals("component")) mappedData.put("group_by", item.getComponent()); else if(sortByField.equals("sub_component")) mappedData.put("group_by", item.getSubComponent()); mappedData.put("asset_type", item.getItemType()); mappedData.put("feature_group", item.getFeatureGroup()); mappedData.put("component", item.getComponent()); mappedData.put("sub_component", item.getSubComponent()); mappedData.put("asset_id", item.getId()); mappedData.put("asset_subject", item.getName()); mappedData.put("reference_maps", item.getReferenceMap());//Used for the table in the content mappedData.put("release_notes", item.getReleaseNotes()); mapDataSource[i] = mappedData; } dataSource = new JRMapArrayDataSource(mapDataSource); return dataSource; }[/code] This is the method that generates the main report, and which the DataSource instance is been passed to: public static void GenerateReport(JRDataSource dataSource, String reportWarnings, boolean includePreface) throws JRException { // Holds compiled jrxml file. JasperReport jasperReport; // Holds report after filling process. JasperPrint jasperPrint; HashMap<String, Object> jasperParameter = new HashMap<String, Object>(); jasperParameter.put("report_title", reportTitle); jasperParameter.put("product_version", productVersion); jasperParameter.put("build_number_from", buildFromLabel); jasperParameter.put("build_number_to", buildToLabel); jasperParameter.put("report_logo", reportLogoPath); /sperParameter.put("data_source", dataSource); jasperParameter.put("report_book_pages_dir", reportBookPagesDir); jasperParameter.put("report_book_images_dir", reportBookImagesDir); //jasperParameter.put("report_book_pages_dir", reportLogoPath); if(includePreface) { jasperParameter.put("preface", ReadPreface()); } jasperParameter.put("warnings", reportWarnings); jasperReport = JasperCompileManager.compileReport(reportTemplatePath); jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, dataSource); //Create the file dir File file = new File(reportOuputPath); file.getParentFile().mkdirs(); //file.delete(); JasperExportManager.exportReportToPdfFile(jasperPrint, reportOuputPath); }[/code] OK, I believe this is information enough, but let me know if you need more details and I will gladly share more... I believe my problems is not passing correctly the DataSource to the sub-report therefore, fields are getting nulls values. Would you please help me? Thank in advance! PS. Sorry about the post format I am kind of new posting in this blog...
×
×
  • Create New...