Jump to content
Changes to the Jaspersoft community edition download ×

doubts in JasperReports and iReport


2005 IR Help

Recommended Posts

By: Dhinesh Kumar P - dhindu

doubts in JasperReports and iReport

2004-11-02 02:49

hi,

 

I want to create a report using JasperReports having hyperlinks to links in local page and also in remote page. Im using iReport to design the report and JasperReports to fill and export the report. Im having some doubts in both iReport and JasperReports.

 

1. how can I give the hyperlink during runtime based on some conditions. Is it possible in either JasperReports or iReport?

 

2. Is it possible to display the report in table structure?

 

3. How can I give a different background color for a particular text field based on some conditions during filling the reports? Is it possible either in iReports or JasperReports?

 

the following 2 doubts are in seperate reports.

4. I created a report having rectangles and ellipses using iReport and viewed it using iReport. it worked successfully. but if I compile that jrxml file generated by the iReport with JasperReports im getting null pointer exception. it looks like it not getting any graphic element from the iReport file. The console output is as below:

going to compile

compilation successful

element.length = 0

java.lang.NullPointerException

at runtimereport.RunTimeReport.main(RunTimeReport.java:53)

 

the program is as below:

public class RunTimeReport {

public static void main(String[] args) {

String objSourceFile = "E:\JasperReports/reports/runtimereport/chumma.jrxml";

String objSourceFile1 = "E:\JasperReports/reports/runtimereport/chumma.jasper";

try {

// cpmpilation of jrxml file

System.out.println("going to compile");

JasperCompileManager.compileReportToFile("E:\JasperReports/reports/runtimereport/demo2.jrxml");

System.out.println("compilation successful");

//filling the jasper file

File objFile = new File(objSourceFile1);

JasperReport objJasperReport = (JasperReport)JRLoader.loadObject("E:\JasperReports/reports/runtimereport/Demo2.jasper");

JRElement elements[] = objJasperReport.getTitle().getElements();

System.out.println("element.length = " + elements.length);

JRElement element = null;

List list = objJasperReport.getTitle().getChildren();

Iterator iterator = list.iterator();

while(iterator.hasNext()) {

System.out.println("iterator.next().getClass() = " + iterator.next().getClass());

}

 

JRRectangle objJRRectangle = (JRRectangle)objJasperReport.getTitle().getElementByKey("FirstRectangle");

objJRRectangle.setBackcolor(new Color((int)(16000000 * Math.random())));

objJRRectangle.setForecolor(new Color((int)(16000345 * Math.random())));

 

objJRRectangle = (JRRectangle)objJasperReport.getTitle().getElementByKey("SecondRectangle");

objJRRectangle.setBackcolor(new Color((int)(25000000 * Math.random())));

objJRRectangle.setForecolor(new Color((int)(25000345 * Math.random())));

 

JREllipse objJREllipse = (JREllipse)objJasperReport.getTitle().getElementByKey("FirstEllipse");

objJREllipse.setBackcolor(new Color((int)(10000000 * Math.random())));

objJREllipse.setForecolor(new Color((int)(10000000 * Math.random())));

 

 

JasperPrint objJasperPrint = JasperFillManager.fillReport(objJasperReport, null, (Connection)null);

 

File objDestFile = new File(objFile.getParent(), objJasperReport.getName() + ".jrprint");

JRSaver.saveObject(objJasperPrint, objDestFile);

 

//exporting the file

JasperExportManager.exportReportToHtmlFile(objJasperPrint, objJasperReport.getName());

System.out.println("successful");

} catch (JRException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

}

}

 

5. I'm using a resultset datasource. The doubt is my resultset is having some columns like ?Version Mismatch?. If I declare this field im getting the following compilation error while compiling it in iReport. Is there any other work around to specify the column names with white spaces? I also tried the backslash characters but in vain.

 

Compiling to file... .h_index.jasper -> .h_index.java

Errors compiling .h_index.jasper!

 

org.xml.sax.SAXParseException: NMTOKEN/NMTOKENS values must be XML name tokens; "Version Mismatch" is not one.

at org.apache.crimson.parser.Parser2.error(Unknown Source)

at org.apache.crimson.parser.ValidatingParser.validateAttributeSyntax(Unknown Source)

at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)

at org.apache.crimson.parser.Parser2.content(Unknown Source)

at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)

at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)

at org.apache.crimson.parser.Parser2.parse(Unknown Source)

at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)

at org.apache.commons.digester.Digester.parse(Digester.java:1514)

at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:400)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:384)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:338)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:322)

at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:128)

at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:336)

at java.lang.Thread.run(Unknown Source)

NESTED BY :

net.sf.jasperreports.engine.JRException: NMTOKEN/NMTOKENS values must be XML name tokens; "Version Mismatch" is not one.

at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:404)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:384)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:338)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:322)

at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:128)

at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:336)

at java.lang.Thread.run(Unknown Source)

Caused by: org.xml.sax.SAXParseException: NMTOKEN/NMTOKENS values must be XML name tokens; "Version Mismatch" is not one.

at org.apache.crimson.parser.Parser2.error(Unknown Source)

at org.apache.crimson.parser.ValidatingParser.validateAttributeSyntax(Unknown Source)

at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)

at org.apache.crimson.parser.Parser2.content(Unknown Source)

at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)

at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)

at org.apache.crimson.parser.Parser2.parse(Unknown Source)

at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)

at org.apache.commons.digester.Digester.parse(Digester.java:1514)

at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:400)

... 6 more

 

Compilation running time : 491

 

How can i overcome these problems either in JasperReports or in iReports?

 

The demo sample programs is confusing me as iam new to both JasperReports and iReport. can some one send me some sample code in JasperReports to overcome these problems?

 

Thanks in advance.

 

Regards,

Dhinesh Kumar P

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...