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

Tom C

Jaspersoft Staff
  • Posts

    453
  • Joined

  • Last visited

Community Answers

  1. Tom C's post in How to launch report having multiple sub reports using Java was marked as the answer   
    import net.sf.jasperreports.engine.JRDataSource;
    import net.sf.jasperreports.engine.JREmptyDataSource;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.engine.JasperReport;
    import net.sf.jasperreports.engine.util.JRLoader;
    import net.sf.jasperreports.view.JasperViewer;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.HashMap;
    import java.util.Map;
    public class JasperReportWithSubreports {
        public static void main(String[] args) {
            // Create a connection to your database
            Connection connection = createDatabaseConnection();
            // Load the compiled main Jasper report (.jasper file)
            JasperReport mainReport = loadCompiledReport("path/to/main/report.jasper");
            // Load the compiled subreport (.jasper file)
            JasperReport subReport = loadCompiledReport("path/to/sub/report.jasper");
            // Set parameters for the main report
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("ReportTitle", "Sample Report");
            parameters.put("CompanyName", "ABC Corp");
            parameters.put("subReportParameter", subReport); // Pass the subreport to the parameter
            // Fill the main report with data using a JRDataSource implementation
            JRDataSource dataSource = createDataSource();
            JasperPrint jasperPrint = null;
            try {
                jasperPrint = JasperFillManager.fillReport(mainReport, parameters, dataSource);
            } catch (Exception e) {
                e.printStackTrace();
            }
            // Display the report in a viewer (optional)
            if (jasperPrint != null) {
                JasperViewer.viewReport(jasperPrint, false);
            }
            // Close the database connection
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        // ... Same createDatabaseConnection, createDataSource methods as before ...
        private static JasperReport loadCompiledReport(String reportFilePath) {
            JasperReport jasperReport = null;
            try {
                jasperReport = (JasperReport) JRLoader.loadObjectFromFile(reportFilePath);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return jasperReport;
        }
    }
     
  2. Tom C's post in ibcosoftware.jdbc.autorest.AutoRESTDriver cannot be found was marked as the answer   
    "jasperreports-server-cp-8.0.0" is a package for the open source community edition which does not contain licensed components. You will need to get a JRS commercial edition (AKA enterprise/professional edition) to use this licensed "TIautorest-6.0.0.004291.jar" through a product subscription. . 
  3. Tom C's post in Why so much unused space, engine is skipping to a new page even if a lot of data could fit on the current page was marked as the answer   
    This looks like a defect when JasperReports engine (JRL) calculates the remaining space on a page involving the RemoveLineWhenBlank property.
    The work around is to put your image in the second detail band and use band print when condition to determine whether the band will be called to display the image. This will avoid relying on RemoveLineWhenBlank property to shrink the band height causing the miscalculation.

  4. Tom C's post in Date extraction on string date type was marked as the answer   
    Please try:
    SELECT STR_TO_DATE(invoices.invoice_date,'%Y-%m-%d') as invoices_invoice_date from your_table
    This will convert date string in your String type column "invoice_date" into a Date type data in the query result set. You can then use a date range comparison in your SQL query to select records based on invoices_invoice_date values.
    Please refer to MySQL reference material for SQL coding information. The following MySQL posting might be useful:
    http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html
  5. Tom C's post in I wanna make a report which is simple.IT should list all of employees but it just list one row?Why any idea was marked as the answer   
    Assuming you indeed have more than one record in your query resultant dataset, most likely you did not display the record field in Detail section of the report. If, for example, the field is displayed in report Title band, you will only see the first record from the result set in the report. If, on the other hand, it is displayed in the Summary band, then you will only see the last record from the result set in your report.
  6. Tom C's post in Sort data within a group (alphabetically) between 2 columns (taking page breaks into consideration) was marked as the answer   
    The proposed approach only works in a single page. Sorry that my sample report might be misleading since it was based on the specific data provided in your question that happens to have report data evenly divided among two report pages thus a fix page height can be applied to both page layouts. In general, JasperReports engine is not able to help layout the report based on your requirement because:
    1) report height is defined at design time and cannot be changed during report execution;
    2) multiple column report layout is based on the available space in the section to determine the column height. It is not capable of auto adjusting the column height to display report content evenly among multiple columns.
    There's no simple solution to meet your design requirement using JasperReports product. The pixel measurement used in JR report layout, compounded by field overflow stretch, makes it impossible to determine how many characters can fit into a report page in order to evenly layout field content in multiple column with one pass data processing.
  7. Tom C's post in same detail shown multiple times in a page and in multiple pages(iReports as well as JasperSoft Studio was marked as the answer   
    Where did you put the table and chart element in the report? They should be placed in SUMMARY section, not detail section.  JR report detail band is called for each row fetched into report. If you have 100 rows, it will display information in the detail band 100 times each with details of that row. Tables and charts gather and tally all your data to display and should be placed in the summary band thus have them displayed only once.
  8. Tom C's post in Sequence number in iReport was marked as the answer   
    Here is the sample report design template to demo the approach. You can test run this report using any PostgreSQL data source. It was created using iReport 5.6 but it should work with Jasper Studio as well.
    <?xml version="1.0" encoding="UTF-8"?><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="demo for vspn" language="groovy" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5fa71407-8d68-4ece-8349-60dded252ccc"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <queryString> <![CDATA[select '620592' as Facility, 'S0722' as Store, 1 as Stopunion allselect '620578' as Facility, 'S0308' as Store, 2 as Stopunion allselect '620578' as Facility, 'S0631' as Store, 3 as Stopunion allselect '620590' as Facility, 'S0678' as Store, 4 as Stopunion allselect '620590' as Facility, 'S0444' as Store, 5 as Stopunion allselect '620590' as Facility, 'S0237' as Store, 6]]> </queryString> <field name="facility" class="java.lang.String"/> <field name="store" class="java.lang.String"/> <field name="stop" class="java.lang.Integer"/> <variable name="Sequence" class="java.lang.Integer" incrementType="Group" incrementGroup="groupFacility" calculation="Count"> <variableExpression><![CDATA[$F{facility}]]></variableExpression> </variable> <group name="groupFacility"> <groupExpression><![CDATA[$F{facility}]]></groupExpression> </group> <background> <band splitType="Stretch"/> </background> <title> <band splitType="Stretch"/> </title> <pageHeader> <band splitType="Stretch"/> </pageHeader> <columnHeader> <band height="25" splitType="Stretch"> <staticText> <reportElement x="0" y="0" width="100" height="20" uuid="c371c0da-2c48-484d-99f1-efddf3d7eabc"/> <text><![CDATA[Facility]]></text> </staticText> <staticText> <reportElement x="100" y="0" width="100" height="20" uuid="08071704-3eed-41d2-bf72-2757aa1a69db"/> <text><![CDATA[stop]]></text> </staticText> <staticText> <reportElement x="200" y="0" width="100" height="20" uuid="5c55f9e4-4d41-46d6-b941-c0cb0c81f946"/> <text><![CDATA[sequence]]></text> </staticText> </band> </columnHeader> <detail> <band height="24" splitType="Stretch"> <textField> <reportElement x="0" y="0" width="100" height="20" uuid="43d664a7-471e-4cb8-889b-31a4cda9f589"/> <textFieldExpression><![CDATA[$F{facility}]]></textFieldExpression> </textField> <textField> <reportElement x="100" y="0" width="100" height="20" uuid="0e67a151-1a70-4b93-b78c-4773c767b89c"/> <textFieldExpression><![CDATA[$F{stop}]]></textFieldExpression> </textField> <textField> <reportElement x="200" y="0" width="100" height="20" uuid="55968736-2d84-4c71-a85f-d99674f06b70"/> <textFieldExpression><![CDATA[$V{Sequence}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band splitType="Stretch"/> </columnFooter> <pageFooter> <band splitType="Stretch"/> </pageFooter> <summary> <band height="25" splitType="Stretch"> <line> <reportElement x="0" y="0" width="300" height="1" uuid="57ba23ee-04c1-42af-a231-e17158e5eeee"/> </line> <staticText> <reportElement x="100" y="5" width="100" height="20" uuid="0d4e0c10-b06c-4014-8e1c-43a30eabe5e2"/> <textElement> <font isBold="true"/> </textElement> <text><![CDATA[TOTAL RECORDS:]]></text> </staticText> <textField> <reportElement x="200" y="5" width="100" height="20" uuid="f53e8c67-193a-41d7-b0de-e66ad3770eb1"/> <textElement> <font isBold="true"/> </textElement> <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression> </textField> </band> </summary></jasperReport>Here is the screen shot of the report output:

  9. Tom C's post in Get a sum of amounts according to another field was marked as the answer   
    JR engine can do tally on a single field (in your case $F(Amount}), but it cannot tally field value based on another value (in you case $F{Currency}). You will have to tell JR how to keep track of each $F(Amount} based on $F{Currency} value. If we can assure that each page of your report only has one currecncy type, then you can simply sum $F(Amount} in a variable with reset type to page. But this will not help to show all currency totals in the summary in one single tally variable. JR does not know the relationship between $F(Amount}) and $F{Currency} - you have to tell it to track all currency totals for the report, for example tracking USD currency total for the report in $F{Total_USA}:
    <variable name="Total_US" class="java.math.BigDecimal" calculation="Sum"> <variableExpression><![CDATA["USD".equals($F{currency})?$F{amount}:$V{zero}]]></variableExpression> </variable>[/code].. so as to track other currencies in seperate sum variables.
    To satisfy your report design requrement, you will need to find a way to keep track of all possible 100+ currencies and tally them individually. The suggested approaches can be:
    1) Rewirite your SQL query to provide all individual currency amounts in the record as Amount_USD, Amount_CanadianDollar,  Amount_MexicanPeso,...etc, thus JR can simply tally each individual amount field to provide page and report level summary information;
    2) Create individual summary variables in the report for all possible currencies for page and report tally (as demonstrated in my previous answer);
    3) Create a variable collection or an array in the report to track currency amount individually as the records come in, and tally them manually for report and page summary. This can be acheived by a Java class method inheriting JR as a scriptlet and use it in the report template.
     
    The first two approaches are relatively simple, but tedious. The last suggestion requires Java programming effort with advanced JR knowledge to make it work - I do not have a sample code to show the approach but it should work (please understand the posting provided here are volunteer based and we do not always have time to write demo code). Hope this helps to explain and clarify the situation.
  10. Tom C's post in How to connect sql server JDBC with database name containing space was marked as the answer   
    Please try::
    databaseName={Astrindo Starvision [Operational]_140804}
  11. Tom C's post in Using return value of a subreport to make calculations was marked as the answer   
    Indeed, this is a timing issue when variable is evaluated before the sub report call. I would suggest either do the calculation in the display field where evelaution time can be controled, or pass and sum the tally inside sub report and return cumulative sum back to the main report.
  12. Tom C's post in Header without data on page was marked as the answer   
    I am not sure how you have implemented this two sub reports in the main report. You can certainly use group minHeightToStartNewPage property setting or put them into two separate detail bands to meet  your report design requirement. In the group approach, you need to make sure the minimum height set in the main report group header is the page height of your sub report, not the field height of your sub report column. In the two detail band approach, you need to make sure the height of the detail band hosting your sub report must be no less than sub report height itself and detail band is set to stretch.
  13. Tom C's post in $V{PAGE_NUMBER} Not respecting evaluation time was marked as the answer   
    Make sure your text field has enough height and width to contain at least one character of your font size - if you cannot see a single field content (such as a $ sign) displayed in the report designer, your field height is not large enough. In your case, increase the height to 20 or decrease font size will fix the problem and allow total page count display in the report page footer.
  14. Tom C's post in How to crate a dammy group that breaks on each page? was marked as the answer   
    What Teodor said in the previous community posting is:
    1) JR report page footer cannot stretch;
    2) JR report group can start at a new page on group breaks;
    3) JR report footer can stretch and be placed at the bottom of the page.
    To meet your report requirement that needs to have variable height page footers, one approach is to utilize group footer to hold report page footer content with various text lengths. The tricky part, however, is how to trigger the group break. I am not sure how you designed your report using the group that you see no page breaks when group changes. But in general, you should not use report system variable $V{PAGE_NUMBER} for your page break because as Teodor mentioned in his comment, the group break "needs to start sooner/upper on the page", so that your group footer will have enough room to display its content on the current page without overflowing into another page. Once you reach the page break. as indicated by $V{PAGE_NUMBER} increment, it is too late to lay your group footer on the page.
    There's no easy way to use group footer to achieve a dynamic report design to meet your requirement. You will need to set up some hard rules to determine how to make the group break, such as number of detail records per page, etc, and test the approach to come up with the best design solution.
  15. Tom C's post in Date function compile problem was marked as the answer   
    DateFormat is an abstract Java class. You need to use one of the static factory methods through getDateInstance() instantiation to format a date for the current Locale, such as
    DateFormat.getDateInstance().format($F{productDate})
    To format your productDate field from SQL query resultant data set into "EEEE dd MMMM yyyy" pattern in the report display, you will need to first create a SimpleDateFormat object using your display pattern (new java.text.SimpleDateFormat("EEEE dd MMMM yyyy") then use this SimpleDateFormat object to format your date field .format($F{productDate}).
    But ....... Why? JasperReports already has the build Date format function to do this for you. You can simply display your productDate field in the report with  "EEEE dd MMMM yyyy" pattern:
     
    <textField pattern="EEEE dd MMMM yyyy">...... <textFieldExpression><![CDATA[$F{productDate}]]></textFieldExpression> </textField>[/code]
    Please give a try and this should work for all SQL date/time/timestamp types  (and save you a lot of trouble by coding the date formatter yourself).
     
  16. Tom C's post in JasperSoft Studio 6 Images was marked as the answer   
    To make image availbale for report unit to render from JRS web application, you can either 1) upload your image into JRS repository as an image file under Public folder and use "repo:/..." reference in the report image expression in your report desgin, or 2) place the image file in a web server content folder and reference it with a URL in your report image expression (something like "http://localhost:8080/..../yourImage.png".
  17. Tom C's post in How to change the labels in jasper report charts? was marked as the answer   
    Since the reason label is based on report data row retreival sequence, you can use $V{REPORT_COUNT} in chart series or categories expression to meet your requirement:
    "Reason "+$V{REPORT_COUNT}


  18. Tom C's post in Can Subreport Solve this Issue was marked as the answer   
    You do not need to use sub report to produce the report as per your design requirement. Please take a look at this wiki article for a sample report based on your requirement:
    http://community.jaspersoft.com/wiki/sample-report-using-one-report-template-display-summary-and-detail-group-data
     
  19. Tom C's post in Can't create a chart theme with iReport was marked as the answer   
    Please use iReport 5.5 or Jasper Studio 6.0 to create chart theme template.
  20. Tom C's post in iReport-5.6.0 does not open was marked as the answer   
    Can you launch your iReport 5.6 from the command line and see if you get any error? For example, from command prompt at your deployed iReport-Professional-5.6.0bin folder location, type "ireportpro.exe".
  21. Tom C's post in difference between Data Staging and Data Snapshot was marked as the answer   
    Data staging is to store the entire dataset for a Domain Topic in the server's Ad Hoc cache. Data snapshot is the stored report data in the server coming from any report execution.
  22. Tom C's post in Difference between .jrxml and .jasper files ? was marked as the answer   
    .jasper file is a Java executable and it is used in JVM to generate report based on your report design. Jaspersoft report design tools recognize this file type as a JR specific Java class file and is able to convert the files back to report template in XML format. JSS does the conversion automatically while iReport prompts for a user confirmation before the process. It's just different approaches to the same capability by our product.
  23. Tom C's post in Issue with new user/role? was marked as the answer   
    ROLE_USER is a special system-level role that is equired to allow a user to log in. You should never delete this role.
    If you want to set the resource access permission for your test_user, assinging both ROLE_USER and TEST_ROLE roles to  this user. Then set permission of your repository resource to "No access" for ROLE_USER, and RWD access for TEST_ROLE.
  24. Tom C's post in Title only reported on the first page was marked as the answer   
    Report title will only show once in your report layout. Use page header to put your information on the top of every report page. Please refer to iReport ultimate Guide section 4.1 "Bands" for detail.
    Free documentation download link from Jaspersoft Community site::
    https://community.jaspersoft.com/documentation?version=10870
     
     
  25. Tom C's post in total gets printed on new page was marked as the answer   
    Please refer to this wiki article for a sample report:
    http://community.jaspersoft.com/wiki/how-keep-last-report-record-and-report-summary-information-together-even-when-pagination-occurs
×
×
  • Create New...