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

reportdev

Members
  • Posts

    413
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Posts posted by reportdev

  1. I'm using JFrame here, but you can change it to something else. 

        public static void main(String[] args) throws ParseException, SQLException, JRException {        Connection con = DriverManager.getConnection("jdbc:oracle", "user","password");        java.sql.Date sqlDate = new java.sql.Date((new SimpleDateFormat("MM/dd/yyyy").parse("07/01/2018")).getTime());        Map parameters = new HashMap();        Map<String, String> temp = new HashMap<String, String>();        parameters.put("paramName", sqlDate);         String workingDir = System.getProperty("user.dir");        String file = workingDir + "\src\resources\main_jrxml.jasper";         System.out.println("Current working directory : " + file);        JasperReport report = (JasperReport) JRLoader.loadObjectFromFile(file);        JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, con);        JFrame frame = new JFrame("Report");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.getContentPane().add(new JRViewer(jasperPrint));        frame.pack();        frame.setVisible(true);    }}[/code]

     

  2. That was really a good question, have been working on Jasper for awhile for but did not ask myself that question.

    Here is your answer: https://community.jaspersoft.com/documentation/tibco-jaspersoft-studio-user-guide/v640/datasets-and-subdatasets

    In short, you cannot use the main dataset for the tables/charts/tables. 

     

    If you do not want to make two calls to the database, then you can use this below strategy. (i'm using Oracle database, but you can find same functionality in other databases too)

    • The main dataset will initiate the report connection with "select * from dual"
    • Write your main query in the sub dataset. Send the same REPORT_CONNECTION to the sub dataset. 
  3. Create a new dataset in your report called as parameter count

    Use the same sql as the parameter is using, instead of getting any columns, get a count of parameter values

    Create a Table element based on the above dataset and write a ternary expression to display the "ALL" or Something else.

    Here is a sample jrxml

    <?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.4.2.final using JasperReports Library version 6.4.1  --><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="parameterCount" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="afcffb2c-62fc-41ec-9f38-8f5ffbf1e460">    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>    <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">        <box>            <pen lineWidth="0.5" lineColor="#000000"/>            <topPen lineWidth="0.5" lineColor="#000000"/>            <leftPen lineWidth="0.5" lineColor="#000000"/>            <bottomPen lineWidth="0.5" lineColor="#000000"/>            <rightPen lineWidth="0.5" lineColor="#000000"/>        </box>    </style>    <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">        <box>            <pen lineWidth="0.5" lineColor="#000000"/>            <topPen lineWidth="0.5" lineColor="#000000"/>            <leftPen lineWidth="0.5" lineColor="#000000"/>            <bottomPen lineWidth="0.5" lineColor="#000000"/>            <rightPen lineWidth="0.5" lineColor="#000000"/>        </box>    </style>    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">        <box>            <pen lineWidth="0.5" lineColor="#000000"/>            <topPen lineWidth="0.5" lineColor="#000000"/>            <leftPen lineWidth="0.5" lineColor="#000000"/>            <bottomPen lineWidth="0.5" lineColor="#000000"/>            <rightPen lineWidth="0.5" lineColor="#000000"/>        </box>    </style>    <subDataset name="paramCount" uuid="da6302aa-23ff-4f8c-ba13-809fe1a79241">        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>         <parameter name="arrayListParam" class="java.util.ArrayList">            <defaultValueExpression><![CDATA[Arrays.asList("1", "2", "3")]]></defaultValueExpression>        </parameter>        <queryString language="SQL">            <![CDATA[select count(*) as totalCount from (    select 1 from dual union     select 2 from dual union     select 3 from dual )]]>        </queryString>        <field name="TOTALCOUNT" class="java.math.BigDecimal"/>    </subDataset>    <parameter name="arrayListParam" class="java.util.ArrayList">        <defaultValueExpression><![CDATA[new ArrayList(Arrays.asList("1", "2", "3"))]]></defaultValueExpression>    </parameter>    <queryString>        <![CDATA[select * from dual]]>    </queryString>    <field name="DUMMY" class="java.lang.String"/>    <background>        <band splitType="Stretch"/>    </background>    <title>        <band height="30" splitType="Stretch">            <staticText>                <reportElement x="0" y="0" width="802" height="30" uuid="79b34a17-1afc-4f38-a307-b09ef0af02ca"/>                <text><![CDATA[Parameter All]]></text>            </staticText>        </band>    </title>    <detail>        <band height="30" splitType="Stretch">            <componentElement>                <reportElement x="0" y="0" width="802" height="30" uuid="dbadd6a6-8363-411e-a34f-6736d5c0f7c3">                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>                    <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>                    <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>                    <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>                </reportElement>                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">                    <datasetRun subDataset="paramCount" uuid="81c160d1-35bf-4abd-a6e9-a87f7a0338d8">                        <datasetParameter name="arrayListParam">                            <datasetParameterExpression><![CDATA[$P{arrayListParam}]]></datasetParameterExpression>                        </datasetParameter>                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>                    </datasetRun>                    <jr:column width="200" uuid="0651b07b-5ea1-4d1b-990e-ccb134c9b7fb">                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>                        <jr:detailCell style="Table_TD" height="30">                            <box>                                <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                                <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                                <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                                <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                            </box>                            <textField>                                <reportElement x="0" y="0" width="200" height="30" uuid="ba8e0370-1610-4fdd-aac8-4bce9911c3b5"/>                                <textElement>                                    <font size="14"/>                                </textElement>                                <textFieldExpression><![CDATA[$F{TOTALCOUNT}.intValue() == $P{arrayListParam}.size() ? "All" : $P{arrayListParam}]]></textFieldExpression>                            </textField>                        </jr:detailCell>                    </jr:column>                </jr:table>            </componentElement>        </band>    </detail></jasperReport>[/code]

     

     

  4. You need to add a style to the jrxml.

    Add below code after JRXML properties like this. 

    <style name="RowBanding">
            <conditionalStyle>
                <conditionExpression><![CDATA[$V{REPORT_COUNT}%2==0]]></conditionExpression>
                <style mode="Opaque" backcolor="#F2F2F2"/>
            </conditionalStyle>
        </style>

     

    Then apply the Style Rowbanding to the Text Fields in detail band

  5. @Matthew... remove the Correct Answer Tag from Hozawa's post if you feel you did not get the answer,

    so that Other users can comment on this post. Otherwise it not allowing other users to answer.

    Below is the code that i wrote in java for the same purpose... try to salvage some code and write your own scriptlet in jasper reports.

    /*Imports :
    Commons-beanutils
    Commons-digester
    Commons-logging
    Jasperreports
    Ojdbc
    Org.apache.commons.collections
     */ 

    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.HashMap;
    import java.util.Map;

    import javax.swing.JFrame;

    import com.lowagie.text.Document;
    import com.lowagie.text.DocumentException;
    import com.lowagie.text.pdf.PdfCopy;
    import com.lowagie.text.pdf.PdfImportedPage;
    import com.lowagie.text.pdf.PdfReader;
    import com.lowagie.text.pdf.PdfWriter;

    import net.sf.jasperreports.engine.JRException;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.engine.JasperReport;
    import net.sf.jasperreports.engine.export.JRPdfExporter;
    import net.sf.jasperreports.engine.util.JRLoader;
    import net.sf.jasperreports.export.ExporterInput;
    import net.sf.jasperreports.export.SimpleExporterInput;
    import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
    import net.sf.jasperreports.export.SimplePdfExporterConfiguration;
    import net.sf.jasperreports.swing.JRViewer;

    public class JasperReportFillWithSplitPDF {
        @SuppressWarnings("unchecked")
        public static void main(String[] args) throws SQLException, IOException, DocumentException {
            try {
                Connection con = DriverManager.getConnection("jdbcConnectionStrings); // opens a jdbc connection


                String reportName =  "reportJrxml";

                JasperReport report = (JasperReport)
                        JRLoader.loadObjectFromFile("C:/" + reportName + ".jasper");

                Map  parameters = new HashMap();     
                
                JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, con);

                JFrame frame = new JFrame("Report");
                frame.getContentPane().add(new JRViewer(jasperPrint));
                frame.pack();
                frame.setVisible(true);


                JRPdfExporter exporter = new JRPdfExporter();
                ExporterInput inp = new SimpleExporterInput(jasperPrint);
                exporter.setExporterInput(inp);
                exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(reportName + ".pdf"));
                SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
                configuration.setPermissions(PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY);
                exporter.setConfiguration(configuration);
                exporter.exportReport();
                exporter.setExporterOutput(null);
                
                String inFile = new String(reportName + ".pdf");
                PdfReader reader = new PdfReader(inFile);
                int n = reader.getNumberOfPages();
                int i = 0;
                 while ( i < n ) {
                        String outFile = inFile.substring(0, inFile.indexOf(".pdf"))
                            + "-" + String.format("%03d", i + 1) + ".pdf";
                        System.out.println ("Writing " + outFile);
                        Document document = new Document(reader.getPageSizeWithRotation(1));
                        PdfCopy writer = new PdfCopy(document, new FileOutputStream(outFile));
                        document.open();
                        PdfImportedPage page = writer.getImportedPage(reader, ++i);
                        writer.addPage(page);
                        document.close();
                        writer.close();
                    }

            }
            catch (JRException e) {
                e.printStackTrace();
            }
        }
    }

     

     

     

  6. First Read this https://community.jaspersoft.com/wiki/how-use-multiple-data-sources-jaspersoft-studio-or-jasperreports-server

    and if not working then

    I think this is possible. but it needs some java coding.

    Main dataset would query Excel spreadsheet - this is normal

    Subreport dataset would query Oracle - this is where it gets tricky

    usually the same connection string is passed in to the subreport from the main report.

    but here two different datasources should be used, so REPORT_DATA_SOURCE parameter for the subreport from main report should be set to Oracle. 

    If you are using java to generate this report, then you can pass this REPORT_DATA_SOURCE (JRDataSource object) parameter into the main report and then pass it into the subreport

     

     

  7. I would suggest

    create a jrxml with a subreport in it.

    • Main report should accept some arraylist as parameter
    • Group based on each arraylist value
    • in the group bands, create a subreport (which is your actual pdf layout)

    when you make a rest call, send the parameter and generate multiple page pdf and 

    then write some code to split multiple page pdf to single page pdf

     

  8. @andrew_50 

    you either need to know how to write a stored procedure or a java scriptlet.

    both the implementations perform the same output. 

    I would suggest you should think about writing a mysql procedure first and then implement it in jasper.

    try writing a mysql procedure which should output a cursor and this cursor can be used for displaying the report.

    inside the same procedure, you should update the records that have been fetched by the cursor.

×
×
  • Create New...