EzDevInfo.com

jasper-reports interview questions

Top jasper-reports frequently asked interview questions

Xerces error: org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl

I'm developing a web application using JSF 2.0, NetBeans 6.9.1, GlassFish Server 3.1, mojarra 2.0.3, and JasperReports 3.7.6. Included in my project library is the jar file "xerces-2.8.0.jar". This file was imported as part of the JasperReports jar file library. Whenever I try to deploy, run, or debug my project through NetBeans, I receive this error:

java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! DTD factory class org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from DTDDVFactory.

After any change in my project my build fails, and I receive the above error, when I try to deploy, run, or debug it. I have to restart the server and run/debug a second time. I've searched the internet and cannot find a solution to this problem. I've looked at the jar file in question, and and DTDDVFactoryImpl does indeed extend from DTDDVFactory - I don't know why I'm receiving this error. While I can eventually get my project running, it would be much nicer if I wasn't receiving this error.

Can anyone please tell me how I can fix this? Do I need to remove this file from my project library? Do I need to update this file with a newer version/older version?


Source: (StackOverflow)

Generating Reports - What works for you? [closed]

I'm looking for a templating tool that allows powerful manipulation of data and report building. JasperReports is powerful, but is it the best out there? I generally don't need the ability for fancy colors or gradients, but I do need the ability to position data accurately and produce reliable, quick results. Ideally, generating a report shouldn't need to be driven by a visual tool, either, and should be entirely API based.

Does anyone have real experience with any major reporting framework in a large scale application? Some of the reporting tools I've seen deal primarily with BusinessIntelligence, and thus less direct programmatic control.

So in summary, I need

  • Strong documentation and support
  • The ability to control document output and print to PDF, programmatically
  • Multiple layout formats
  • Speed and efficiency
  • Ability to last at least 4+ years

and I don't need

  • Pretty colors
  • Rich interfaces (HTML output/etc.)

In general, I'll be producing batch documents, which is why speed and efficiency are very relevant concerns.

Suggestions? Thoughts?


Source: (StackOverflow)

Advertisements

PDF Generation Library for Java

I know this has been asked before, but I'm still undecided on which PDF generation framework to use for my current project.

My requirements

  • on-the-fly generation of PDF documents (mainly order forms, invoices)
  • Java based
  • easy to layout
  • should be open source
  • easy to change layout

A lot of people seem to use iText, but I have some concerns (apart from the changed licence) regarding separation of concerns: In an HTML context there's good MVC support, where I usually stick to Spring MVC and FreeMarker to separate logic and layout. I'm a little bit worried that with iText you end up mixing code and layout a lot.

I am aware, that Apache FOP could be a solution here, but then again I find XSLT tedious to work with and I read that FOP can be slow when it comes to huge throuput of many documents?

I also considered JasperReports, but from my understanding this is more suited for reports containing tabular datasets rather than single documents such as invoices which require a lot of layout formatting?

Any thoughts on this?


Source: (StackOverflow)

Reports in Java. What tool to use? [closed]

I need to create some reports, in different formats (xls, pdf, rtf). I am currently using JasperReports, in conjunction with IReport. I have no major complaints about it (except for the cases when IReport messes up my xml files), but i've been having some problems with it, when exporting to xls files and with some "special" characters, such as '&'.

Is there a widely use alternative? Is JasperReports the right choice?


Source: (StackOverflow)

What are the drawbacks with Jasper Reports? [closed]

I'm evaluating report engines for a Java desktop application. I need to print receipts, invoices and reports. I'm looking at Jasper Reports since it seem to be the most popular reporting engine in the Java world. What are the biggest drawbacks and disadvantages with using it in a small business system?


Source: (StackOverflow)

DynamicReports vs. DynamicJasper [closed]

Background

Developing Java EE application with DynamicReports and so far it's sufficient for me. Recently I found DynamicJasper and I would like to know if it could be better choice.

I can see that DynamicReports may have better support and community.

Questions

  • What have been your experiences with both libraries?
  • Which offers better functionality?
  • What are strengths and weakness of each other?

Thank you!


Source: (StackOverflow)

What are the Maven repositories for Jasper Reports?

Where can I find the Maven repositories for the latest versions of Jasper Reports? I've tried in the main site but it seems that the repo isn't up to date.


Source: (StackOverflow)

JasperReport - wrap text to show long text in textfield

I am using jasper report as reporting tool in my application. And I am wondering how can i wrap the long text by expanding the reportElement dynamically into vertical direction ( expanding the row size, not column width). Or Is there any way to achieve this? My approach below is truncating the long text "Some very long name". Can you please give me some suggestions?

Output :

enter image description here

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;

public class JrUtils {
    public static void showJrReport(List objectList, String fileName, String title, Map parameters) {
        try {

            File f = new File(fileName);
            JasperDesign jasperDesign = JRXmlLoader.load(f.getAbsolutePath());
            JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(objectList);
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
            JasperViewer jv = new JasperViewer(jasperPrint, false);
            jv.setTitle(title);
            jv.setVisible(true);

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

        }
    }

    public static void main(String[] args) {
        List<Person> pList = new ArrayList<Person>();

        Person p1 = new Person();
        p1.setPersonName("Some Name ");
        p1.setAddress("Nepal - Address Fits Here");

        Person p2 = new Person();
        p2.setPersonName("Some very long name");
        p2.setAddress("Nepal - Address Fits Here");

        pList.add(p1);
        pList.add(p2);

        showJrReport(pList, "testReport.jrxml", "Test Report", new HashMap<Object, Object>());
    }

}

Jasper Report JrXML file - testReport.jrxml :

<?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="report name" pageWidth="250" pageHeight="400" columnWidth="210" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="2.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <field name="personName" class="java.lang.String"/>
    <field name="address" class="java.lang.String"/>
    <columnHeader>
        <band height="23" splitType="Stretch">
            <rectangle>
                <reportElement x="0" y="0" width="88" height="23"/>
            </rectangle>
            <rectangle>
                <reportElement x="88" y="0" width="122" height="23"/>
            </rectangle>
            <staticText>
                <reportElement x="0" y="0" width="88" height="23"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[Name]]></text>
            </staticText>
            <staticText>
                <reportElement x="88" y="0" width="122" height="23"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[Address]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="21" splitType="Stretch">
            <rectangle>
                <reportElement x="0" y="0" width="88" height="21"/>
            </rectangle>
            <textField>
                <reportElement x="0" y="0" width="88" height="21"/>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{personName}]]></textFieldExpression>
            </textField>
            <rectangle>
                <reportElement x="88" y="0" width="122" height="21"/>
            </rectangle>
            <textField>
                <reportElement x="88" y="0" width="122" height="21"/>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

Source: (StackOverflow)

External Styles in JasperReports

I'm working on a system that includes a large number of reports, generated using JasperReports. One of the newer features is that you can define styles for reports.

From the available docs I believe there is some way to have an external file defining styles to use, and you can reference that in your jasper reports. This allows a single style to be used by multiple reports.

I can't find any concrete information on whether this is an actual feature, and if it is, how to use it. Does anyone know if it is possible to have external styles for jasper reports, and if so, how to do it?

Thanks, Jamie


Source: (StackOverflow)

JasperReports NoClassDefFoundError exception on net.sf.jasperreports.engine.util.JRStyledTextParser

When trying to export on WebLogic 11g, it throws NoClassDefFound exception. I checked the application WAR and jasperreports-3.7.4.jar is included in WEB-INF/lib folder. What is the error?

StackTrace

java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/util/JRStyledTextParser at net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:181) at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:76) at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:86) at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:56) at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:78) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624) at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.fillReport(AbstractJasperReportsView.java:676) at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.renderMergedOutputModel(AbstractJasperReportsView.java:570) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:512) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at javax.servlet.http.HttpServlet.service(HttpServlet.java:821) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265) at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107) at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:73) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:126) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:272) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:111) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249) at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275) at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:150) at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:99) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3588) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2200) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2106) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1428) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)


Source: (StackOverflow)

Jasper Reporting Tutorial [closed]

I am looking for a walkthrough or tutorial for jasper reporting. I have tried searching fortutorials but each tutorial has it's own way of using it. Some are shortcuts and some are incomplete. Can you give me a tutorial or a link which teaches on jasper reporting from setup down to running sample apps


Source: (StackOverflow)

How to avoid null values in jasper reports

I have a field in my jasper report which has a expression value like

$F{address_street1}+" "+$F{address_street2}+ " " +$F{address_state} + " "+$F{address_country}+ " "+$F{address_zip}

My problem is that if any of the fields in here is null I get the null value between other things like

101 Main St****null****ILUnited States12345 

Notice the highlighted null. Is there any way I can avoid that?

I have tried checking the null value for a particular field in it using boolean expression and replacing it with blank, but that doesn't seem to work.


Source: (StackOverflow)

Jasper Reports - how to get column footer to appear directly below details band

I'm trying to get a column footer band to appear directly below a details band.

The details band contains normally just 2 or 3 rows and thus should not be very deep. The footer always appears further down the page and not directly below the end of the content in the details band - therefore the details band is higher than the content it contains. How do I get the details band to collapse to the end of the content so I can get the footer to appear immediately afterwards.

I'm sure this is simply a case of applying some settings - but I can't determine what these are.

Thanks.


Source: (StackOverflow)

How to increase detail band height dynamically

I am using iReport. My requirement is to increase the detail band height dynamically when the text field has more data , are there any settings to increase to it?
I am using one textfield in the detail band when it has more information(words), it is displaying only some information.
i.e the words are being cut off. Depending on the detail band height the words are displaying.I would like to increase the band height dynamically when the text field has more data.

Please advice me on this regard.


Source: (StackOverflow)

How to show an image on jasper report?

I want to show an image on a jasper report. I have the following on the .jrxml:

<image>
  <reportElement x="181" y="0" width="209" height="74"/>
  <imageExpression class="java.lang.String"><![CDATA["logo.jpg"]]></imageExpression>
</image>

The image logo.jpg is in the same directory as the .jrxml. By just putting that it didn't work for me. I googled a bit and found out that jasper report considers what i put on the .jrxml as a relative path to the JVM directory and that to change this I need to pass as a "REPORT_FILE_RESOLVER" parameter a FileResolver that returns the file. So, I did the following in my .java (is located in same place as the .jrxml and the image)

FileResolver fileResolver = new FileResolver() {

 @Override
 public File resolveFile(String fileName) {
  return new File(fileName);
 }
};
HashMap<String, Object> parameters = new HashMap<String, Object>();

parameters.put("REPORT_FILE_RESOLVER", fileResolver);
...

Which should return the expected file, but I still get a

net.sf.jasperreports.engine.JRException: Error loading byte data : logo.jpg
    at net.sf.jasperreports.engine.util.JRLoader.loadBytes(JRLoader.java:301)
    at net.sf.jasperreports.engine.util.JRLoader.loadBytesFromLocation(JRLoader.java:479)
    at net.sf.jasperreports.engine.JRImageRenderer.getInstance(JRImageRenderer.java:180)
...

What am I doing wrong?

Thanks!


Source: (StackOverflow)