Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8605739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:54:48+00:00 2026-06-12T02:54:48+00:00

In my web application I’m generating some reports with JasperReports . In my managed

  • 0

In my web application I’m generating some reports with JasperReports. In my managed bean i have the following report generation code:

public void generateReport(ActionEvent e) { // Inside a Managed Bean
    try {
        pathReport = ReportHelper.reportPath(FacesContext.getCurrentInstance(), "rep_attendees.jasper");
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("EVENT_ID", getEvent().getId());
        param.put("START_DATE", null);
        param.put("END_DATE", null);
        try {
            Properties connectionProps = new Properties();
            connectionProps.put("user", "root");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/MyDB", connectionProps);
            pdfFile = ReportHelper.generateReport(pathRelatorio, parametros, con);
        } catch (Exception ex) {
            log.error(ex.getMessage());
        }
    } catch (Exception ex) {
        log.error(ex.getMessage());
    }

}

Code for the ReportHelper:

public class ReportHelper {

    private static final Logger log = Logger.getLogger(RelatorioHelper.class);


    public static byte[] generateReport(String path, Map<String, Object> param, Connection con) throws FileNotFoundException, JRException, Exception {

        JasperReport rep = null; // 1
        JasperPrint print = null; // 2
        byte[] pdf = null; // 3
        try {
            rep = buildReport(path); // 4
            print = loadReport(rep, param, con); // 5 NEVER RETURNS
            pdf = JasperExportManager.exportReportToPdf(print); // 6 Don't reach this line
        } catch (Exception e) {
            log.error(e.getMessage());
            throw e;
        }
        return pdf;
    }

    public static String reportPath(FacesContext context, String reportName) {
        String repPath = ((ServletContext) context.getExternalContext().getContext()).getRealPath("/resources/reports/") + "/" + reportName;
        return repPath;
    }

    private static JasperReport buildReport(String path) throws FileNotFoundException, JRException {
        return (JasperReport) JRLoader.loadObject(new File(path));
    }

    private static JasperPrint loadReport(JasperReport report, Map<String, Object> param, Connection con) throws JRException {
        return JasperFillManager.fillReport(report, param, con);
    }
}

Here is the report xml:

<?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="SisEventos_RelatorioEvento" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="DATA_INICIO" class="java.util.Date" isForPrompting="false">
    <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<parameter name="DATA_TERMINO" class="java.util.Date" isForPrompting="false">
    <defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<parameter name="ID_EVENTO" class="java.lang.Integer" isForPrompting="false">
    <defaultValueExpression><![CDATA[1]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select idt_evento, nme_evento, dta_inicio_evento, dta_termino_evento, nme_participante, eml_participante from tb_inscricao as t1
 inner join tb_evento as t2 on t1.cod_evento = t2.idt_evento
 inner join tb_participante as t3 on t1.cod_participante = t3.idt_participante
  where (t1.cod_evento = $P{ID_EVENTO} and $P{DATA_INICIO} is not null and $P{DATA_TERMINO} is not null and t2.dta_inicio_evento between $P{DATA_INICIO} and      $P{DATA_TERMINO}) or (t1.cod_evento = $P{ID_EVENTO} and $P{DATA_INICIO} is null and $P{DATA_TERMINO} is not null and t2.dta_termino_evento <= $P{DATA_TERMINO}) or     (t1.cod_evento = $P{ID_EVENTO} and $P{DATA_INICIO} is not null and $P{DATA_TERMINO} is null and t2.dta_inicio_evento >= $P{DATA_INICIO}) or (t1.cod_evento = $P{ID_EVENTO} and $P{DATA_INICIO} is null and $P{DATA_TERMINO} is null)
group by t2.nme_evento order by t2.dta_inicio_evento asc;]]>
</queryString>
<field name="idt_evento" class="java.lang.Integer"/>
<field name="nme_evento" class="java.lang.String"/>
<field name="dta_inicio_evento" class="java.sql.Timestamp"/>
<field name="dta_termino_evento" class="java.sql.Timestamp"/>
<field name="nme_participante" class="java.lang.String"/>
<field name="eml_participante" class="java.lang.String"/>
<group name="gEventos">
    <groupExpression><![CDATA[$F{nme_evento}]]></groupExpression>
    <groupHeader>
        <band height="42">
            <rectangle>
                <reportElement x="25" y="21" width="530" height="20" forecolor="#666666" backcolor="#666666"/>
            </rectangle>
            <staticText>
                <reportElement x="35" y="21" width="267" height="20" forecolor="#FFFFFF"/>
                <textElement textAlignment="Left" verticalAlignment="Middle"/>
                <text><![CDATA[Participante]]></text>
            </staticText>
            <staticText>
                <reportElement x="302" y="21" width="186" height="20" forecolor="#FFFFFF"/>
                <textElement textAlignment="Left" verticalAlignment="Middle"/>
                <text><![CDATA[E-mail]]></text>
            </staticText>
            <staticText>
                <reportElement x="488" y="21" width="68" height="20" forecolor="#FFFFFF"/>
                <textElement textAlignment="Left" verticalAlignment="Middle"/>
                <text><![CDATA[Presente]]></text>
            </staticText>
            <textField isStretchWithOverflow="true">
                <reportElement x="0" y="1" width="270" height="20"/>
                <textElement>
                    <font size="14" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Evento: " + $F{nme_evento}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="270" y="12" width="280" height="1"/>
            </line>
        </band>
    </groupHeader>
    <groupFooter>
        <band height="50"/>
    </groupFooter>
</group>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="60" splitType="Stretch">
        <rectangle>
            <reportElement x="0" y="0" width="200" height="60" forecolor="#E6E6E6" backcolor="#E6E6E6"/>
        </rectangle>
        <staticText>
            <reportElement x="0" y="0" width="200" height="60" forecolor="#666666" backcolor="#FFFFFF"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font fontName="Arial" size="30"/>
            </textElement>
            <text><![CDATA[SisEventos]]></text>
        </staticText>
        <staticText>
            <reportElement x="200" y="35" width="355" height="25"/>
            <textElement textAlignment="Right" verticalAlignment="Middle">
                <font fontName="Arial" size="18" isBold="true" isUnderline="false"/>
            </textElement>
            <text><![CDATA[Relatório de Participantes dos Eventos]]>        </text>
        </staticText>
        <line>
            <reportElement x="200" y="59" width="355" height="1"/>
        </line>
    </band>
</title>
<pageHeader>
    <band height="30" splitType="Stretch">
        <staticText>
            <reportElement x="0" y="5" width="80" height="20"/>
            <textElement>
                <font isBold="true"/>
            </textElement>
            <text><![CDATA[Filtro: ]]></text>
        </staticText>
        <textField isStretchWithOverflow="true">
            <reportElement x="80" y="5" width="475" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA["Data de início: " + (($P{DATA_INICIO} != null) ? $P{DATA_INICIO}.toLocaleString().substring(0, 10) : "Não informada") + " - Data de término: " + (($P{DATA_TERMINO} != null) ? $P{DATA_TERMINO}.toLocaleString().substring(0, 10) : "Não informada")]]></textFieldExpression>
        </textField>
    </band>
</pageHeader>
<columnHeader>
    <band splitType="Stretch"/>
</columnHeader>
<detail>
    <band height="20" splitType="Stretch">
        <rectangle>
            <reportElement x="25" y="0" width="530" height="20" forecolor="#E6E6E6" backcolor="#E6E6E6">
                <printWhenExpression><![CDATA[$V{COLUMN_COUNT}%2==0]]></printWhenExpression>
            </reportElement>
        </rectangle>
        <textField isStretchWithOverflow="true">
            <reportElement x="34" y="0" width="267" height="20"/>
            <textElement textAlignment="Left" verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA[$F{nme_participante}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement x="302" y="0" width="185" height="20"/>
            <textElement verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA[$F{eml_participante}]]></textFieldExpression>
        </textField>
        <rectangle radius="10">
            <reportElement x="500" y="2" width="15" height="15"/>
        </rectangle>
    </band>
</detail>
<columnFooter>
    <band splitType="Stretch"/>
</columnFooter>
<pageFooter>
    <band height="20" splitType="Stretch">
        <textField>
            <reportElement x="355" y="0" width="200" height="20"/>
            <textElement textAlignment="Right" verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA["Página "+$V{PAGE_NUMBER}+" de "+ $V{PAGE_NUMBER}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true" pattern="EEE, dd MMM yyyy - HH:mm:ss" isBlankWhenNull="true">
            <reportElement x="0" y="0" width="200" height="20"/>
            <textElement verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA["Impresso em: " + new java.util.Date().toLocaleString()]]></textFieldExpression>
        </textField>
        <line>
            <reportElement x="0" y="0" width="555" height="1"/>
        </line>
    </band>
</pageFooter>
<summary>
    <band splitType="Stretch"/>
</summary>
</jasperReport>

When he reaches the line 4, a strange thing happens: a tool named org.apache.cataline.startup.bootstrap opens up in my Dock. But when he reaches line 5 and executes, the applications seems to stuck and doesn’t responds. Ok another thing is: i’m using hibernate. How could i get the Connection object (to pass him through the JasperFillManager.fillReport(rep, param, con)) from Hibernate?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:54:49+00:00Added an answer on June 12, 2026 at 2:54 am

    ramkitech.com has found the error! In my application i’m using Maven and the following dependency artifact was being used to import the jasper reports library:

    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>4.7.0</version>
    </dependency>
    

    But i also need the following dependencies:

     <dependency>
            <groupId>com.lowagie</groupId>
            <artifactId>itext</artifactId>
            <version>2.1.7</version>
     </dependency> 
    

    And if you are using groovy as a language (as in my case) in Report then you need to add:

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>1.7.5</version>
    </dependency>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My web application is written using jsp/javascripts. Backend Java. Have managed to implement the
my web application supposed to send email reminders in some point it will send
My web application consists of library type system where books have due dates. I
Web application is deployed, but hits following error message. I am doing with cxf
My web application is based on Google Maps API and I have problems trying
The web application has following prerequisites: Written in PHP Several menues, also a hierarchy
The web application my organization has written to perform customer care functions doesn't have
My web application uses the same database configuration as the application XYZ. I have
My web application uses allot of javascript, and in the javascript I have messages
My web application is a consumer of some internal web services provided by the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.