Précédent   Forum des professionnels en informatique > Logiciels > Solutions d'entreprise > Business Intelligence > Jasper
Jasper Forum d'entraide sur Jasper Reports. Avant de poster --> FAQ Jasper, Tutoriels Jasper
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 20/06/2006, 16h19   #1
Invité de passage
 
Inscription : janvier 2006
Messages : 6
Détails du profil
Informations forums :
Inscription : janvier 2006
Messages : 6
Points : 0
Points : 0
Par défaut [JasperReport] Erreur génération rapport

Salut,
j'ai besoin de générer des rapport a partir de mon application(developpée en java) pour cela j'ai choisi ireport1.0.1 et jasperreports-1.1.1.
mais lorsque je genere mon rapport je tombe sur ce probléme:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
RusReportStarter.startProcess Name=Jasper Report AD_PInstance_ID=1000108 Record_ID=0
 
RusReportStarter.getReportFileName
 
RusReportStarter.processReport - C:\Compiere2\rapport\test.xml
 
RusReportStarter.compileReport- net.sf.jasperreports.engine.JRException: Error at (58, 18: null
 
20 [Thread-5] ERROR digester.Digester - Body event threw exception
 
java.lang.ClassCastException
 
at org.apache.commons.digester.SetNestedPropertiesRule.body(SetNestedPropertiesRule.java:261)
 
at org.apache.commons.digester.Digester.endElement(Digester.java:1006)
 
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
 
at org.apache.xerces.impl.XMLNamespaceBinder.endElement(Unknown Source)
 
at org.apache.xerces.impl.dtd.XMLDTDValidator.endNamespaceScope(Unknown Source)
 
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
 
at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
 
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
 
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
 
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
 
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
 
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
 
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
 
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
 
at org.apache.commons.digester.Digester.parse(Digester.java:1495)
 
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:238)
 
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:225)
 
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:213)
 
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:167)
 
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:151)
 
at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:107)
 
at ru.compiere.report.RusReportStarter.compileReport(RusReportStarter.java:277)
 
at ru.compiere.report.RusReportStarter.processReport(RusReportStarter.java:210)
 
at ru.compiere.report.RusReportStarter.startProcess(RusReportStarter.java:95)
 
at org.compiere.apps.ProcessCtl.startProcess(ProcessCtl.java:449)
 
at org.compiere.apps.ProcessCtl.run(ProcessCtl.java:232)
kiki2000 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/06/2006, 09h17   #2
Invité de passage
 
Inscription : janvier 2006
Messages : 6
Détails du profil
Informations forums :
Inscription : janvier 2006
Messages : 6
Points : 0
Points : 0
slt,
personne n'as une idée sur mon probleme
kiki2000 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/06/2006, 14h32   #3
Invité de passage
 
Inscription : juin 2004
Messages : 3
Détails du profil
Informations forums :
Inscription : juin 2004
Messages : 3
Points : 1
Points : 1
Salut, tu développes une application locale ou web?

Est ce que tu peux poster ton code (tes fonctions, classes, servlet...) en rapport avec la génération.

Brossard est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/06/2006, 10h18   #4
Invité de passage
 
Inscription : janvier 2006
Messages : 6
Détails du profil
Informations forums :
Inscription : janvier 2006
Messages : 6
Points : 0
Points : 0
re salut,
je travaille sur une application locale et je veux introduire jasperreport dedans,
donc j'ai ajoute un répertoire dans lequel j'ai ajouté ma classe et tous les jar répartis respectivement dans 2 répertoire src et lib.

la classe que j'ai ajouté est:

/*
* Class ReportStarter.
*/
package ru.compiere.report;

import org.compiere.process.ProcessCall;
import org.compiere.process.ProcessInfo;
import org.apache.commons.logging.*;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.compiere.util.Trx;

import java.util.*;
import java.sql.*;
import java.io.File;
import java.io.FilenameFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;

import ru.compiere.utils.DBUtils;
import net.sf.jasperreports.engine.*;

public class RusReportStarter implements ProcessCall {
private static File REPORT_HOME = null;
/** Logger */
private static CLogger log = CLogger.getCLogger(RusReportStarter.class);

static {
System.setProperty( "javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
System.setProperty( "org.xml.sax.driver", "org.apache.xerces.parsers.SAXParser");

String reportPath = System.getProperty("ru.compiere.report.path");
if (reportPath == null) {
REPORT_HOME = new File( System.getProperty("COMPIERE_HOME")+"/reports");
} else {
REPORT_HOME = new File( reportPath);
}
}

public boolean startProcess(Properties ctx, ProcessInfo pi, Trx trx) {

String Name=pi.getTitle();
int AD_PInstance_ID=pi.getAD_PInstance_ID();
int Record_ID=pi.getRecord_ID();
/**
* Start the process.
* Called then pressing the Process button in R_Request.
* It should only return false, if the function could not be performed
* as this causes the process to abort.
*
* @param ctx Context
* @param Record_ID Current Record ID
* @param AD_PInstance_ID Process Instance
* @param Name Name of Menu Item
* @return true if success
public boolean startProcess (Properties ctx, String Name, int AD_PInstance_ID, int Record_ID) { */
//Log.trace( Log.l3_Util, "RusReportStarter.startProcess Name="+Name+" AD_PInstance_ID="+AD_PInstance_ID+" Record_ID="+Record_ID);
System.out.println("RusReportStarter.startProcess Name="+Name+" AD_PInstance_ID="+AD_PInstance_ID+" Record_ID="+Record_ID);
ReportData reportData = getReportData( AD_PInstance_ID);
if (reportData==null) {
reportResult( AD_PInstance_ID, "Can not find report data");
return false;
}

String reportPath = reportData.getReportFilePath();
if ((reportPath==null)||(reportPath.length()==0)) {
reportResult( AD_PInstance_ID, "Can not find report");
return false;
}
if (Record_ID!=-1) {
//File reportFile = new File( REPORT_HOME, reportPath);
File reportFile = new File( "C:\\Compiere2\\rapport\\test.xml");

if (reportFile.exists()==false) {
String tmp = "RusReportStarter.startProcess: Can not find report file -"+reportFile.getAbsolutePath();
//Log.error( tmp);
System.out.println(tmp);
reportResult( AD_PInstance_ID, tmp);
return false;
}

JasperData data = processReport( reportFile);
JasperReport jasperReport = data.getJasperReport();
String jasperName = data.getJasperName();
File reportDir = data.getReportDir();

if (jasperReport != null) {
HashMap params = new HashMap( ctx);

// Subreports
File[] subreports = reportDir.listFiles( new FileFilter( jasperName+"Subreport", reportDir, ".xml"));
for( int i=0; i<subreports.length; i++) {
JasperData subData = processReport( subreports[i]);
if (subData.getJasperReport()!=null) {
params.put( subData.getJasperName(), subData.getJasperFile().getAbsolutePath());
}
}

addProcessParameters( AD_PInstance_ID, params);
params.put("RECORD_ID", new Integer( Record_ID));

Language currLang = Env.getLanguage(Env.getCtx());
params.put("CURRENT_LANG", currLang.getAD_Language());
// Resources
File[] resources = reportDir.listFiles( new FileFilter( jasperName, reportDir, ".properties"));
File resFile = null;
// try baseName + "_" + language
for( int i=0; i<resources.length; i++) {
if ( resources[i].getName().equals( jasperName+currLang.getLocale().getLanguage()+".properties")) {
resFile=resources[i];
break;
}
}
if (resFile==null) {
// try baseName only
for( int i=0; i<resources.length; i++) {
if ( resources[i].getName().equals( jasperName+".properties")) {
resFile=resources[i];
break;
}
}
}
if (resFile!=null) {
try {
PropertyResourceBundle res = new PropertyResourceBundle( new FileInputStream(resFile));
params.put("RESOURCE", res);
} catch (IOException e) {
;
}
}

try {
JasperPrint jasperPrint = JasperManager.fillReport( jasperReport, params, DB.getConnectionRW());
if (reportData.isDirectPrint()) {
//Log.trace( Log.l1_User, "RusReportStarter.startProcess print report -"+jasperPrint.getName());
System.out.println("RusReportStarter.startProcess print report -"+jasperPrint.getName());
JasperPrintManager.printReport( jasperPrint, false);
} else {
//Log.trace( Log.l1_User, "RusReportStarter.startProcess run report -"+jasperPrint.getName());
System.out.println("RusReportStarter.startProcess run report -"+jasperPrint.getName());
JasperViewer jasperViewer = new JasperViewer( jasperPrint);
jasperViewer.show();
}
} catch (JRException e) {
//Log.error("RusReportStarter.startProcess: Can not run report - ", e);
System.out.println("RusReportStarter.startProcess: Can not run report - " + e);
}
}

}

reportResult( AD_PInstance_ID, null);
return true;
}

private void reportResult( int AD_PInstance_ID, String errMsg) {
int result = (errMsg==null)?1:0;
errMsg = (errMsg==null)?"":errMsg;
String sql = "update AD_PInstance set result="+result+", errormsg='"+errMsg+"' "+
"where AD_PInstance_ID="+AD_PInstance_ID;
Statement pstmt = null;
try {
pstmt = DB.createStatement();
pstmt.executeUpdate(sql);
pstmt.close();
} catch (SQLException e) {
//Log.error("RusReportStarter.addProcessParameters - "+sql, e);
System.out.println("RusReportStarter.addProcessParameters - "+sql + e);
} finally {
DBUtils.close( pstmt);
}
}

private JasperData processReport( File reportFile) {
//Log.trace( Log.l1_User, "RusReportStarter.processReport - "+reportFile.getAbsolutePath());
System.out.println("RusReportStarter.processReport - "+reportFile.getAbsolutePath());
JasperReport jasperReport = null;

String jasperName = reportFile.getName();
int pos = jasperName.indexOf('.');
if (pos!=-1) jasperName = jasperName.substring(0, pos);
File reportDir = reportFile.getParentFile();
File jasperFile = new File( reportDir.getAbsolutePath(), jasperName+".jasper");
if (jasperFile.exists()) { // test time
if (reportFile.lastModified() == jasperFile.lastModified()) {
try {
jasperReport = JasperManager.loadReport( jasperFile.getAbsolutePath());
} catch (JRException e) {
jasperReport = null;
//Log.error("RusReportStarter.processReport: Can not load report - ", e);
System.out.println("RusReportStarter.processReport: Can not load report - " + e);
}
} else {
jasperReport = compileReport( reportFile, jasperFile);
}
} else { // create new jasper file
jasperReport = compileReport( reportFile, jasperFile);
}

return new JasperData( jasperReport, reportDir, jasperName, jasperFile);
}


private void addProcessParameters( int AD_PInstance_ID, Map params) {
//Log.trace( Log.l1_User, "RusReportStarter.addProcessParameters");
System.out.println("RusReportStarter.addProcessParameters");
String sql = "select ParameterName, "+
"P_String, "+
"P_String_To, "+
"P_Number, "+
"P_Number_To, "+
"P_Date, "+
"P_Date_To "+
"from AD_PInstance_Para where AD_PInstance_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
pstmt.setInt(1, AD_PInstance_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
String name = rs.getString(1);
String pStr = rs.getString(2);
String pStrTo = rs.getString(3);
Double pNum = new Double( rs.getDouble(4));
Double pNumTo = new Double( rs.getDouble(5));
Timestamp pDate = rs.getTimestamp(6);
Timestamp pDateTo = rs.getTimestamp(7);
if (pStr != null) {
if (pStrTo!=null) {
params.put( name+"1", pStr);
params.put( name+"2", pStrTo);
} else {
params.put( name, pStr);
}
} else if (pDate != null) {
if (pDateTo!=null) {
params.put( name+"1", pDate);
params.put( name+"2", pDateTo);
} else {
params.put( name, pDate);
}
} else if (pNum != null) {
if (rs.getBigDecimal(5)!=null) {
params.put( name+"1", pNum);
params.put( name+"2", pNumTo);
} else {
params.put( name, pNum);
}
}
}
} catch (SQLException e) {
//Log.error("RusReportStarter.addProcessParameters - "+sql, e);
System.out.println("RusReportStarter.addProcessParameters - "+sql + e);
} finally {
DBUtils.close( rs);
DBUtils.close( pstmt);
}
}

private JasperReport compileReport( File reportFile, File jasperFile) {
JasperReport res = null;
try {
JasperCompileManager.compileReportToFile( reportFile.getAbsolutePath(), jasperFile.getAbsolutePath());
jasperFile.setLastModified( reportFile.lastModified());
res = JasperManager.loadReport( jasperFile.getAbsolutePath());
} catch (JRException e) {
//Log.error("RusReportStarter.compileReport- ", e);
System.out.println("RusReportStarter.compileReport- " + e);
}
return res;
}

public ReportData getReportData( int AD_PInstance_ID) {
//Log.trace( Log.l1_User, "RusReportStarter.getReportFileName");
System.out.println("RusReportStarter.getReportFileName");
String sql = "SELECT pr.JasperReport, pr.IsDirectPrint from AD_Process pr, AD_PInstance pi "+
"WHERE pr.AD_Process_Id=pi.AD_Process_Id "+
"AND pi.AD_PInstance_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
pstmt.setInt(1, AD_PInstance_ID);
rs = pstmt.executeQuery();
String path = null;
String tmp = null;
boolean directPrint;
if (rs.next()) {
path = rs.getString(1);
tmp = rs.getString(2);
} else {
//Log.error("RusReportStarter.getReportFileName data not found -"+sql);
System.out.println("RusReportStarter.getReportFileName data not found -"+sql);
}
return new ReportData( path, ((tmp.equalsIgnoreCase("y"))?true:false));
} catch (SQLException e) {
//Log.error("RusReportStarter.getReportFileName - "+sql, e);
System.out.println("RusReportStarter.getReportFileName - "+sql + e);
return null;
} finally {
DBUtils.close( rs);
DBUtils.close( pstmt);
}
}

class ReportData {
private String reportFilePath;
private boolean directPrint;

public ReportData(String reportFilePath, boolean directPrint) {
this.reportFilePath = reportFilePath;
this.directPrint = directPrint;
}

public String getReportFilePath() {
return reportFilePath;
}

public boolean isDirectPrint() {
return directPrint;
}
}

class JasperData {
private JasperReport jasperReport;
private File reportDir;
private String jasperName;
private File jasperFile;

public JasperData(JasperReport jasperReport, File reportDir, String jasperName, File jasperFile) {
this.jasperReport = jasperReport;
this.reportDir = reportDir;
this.jasperName = jasperName;
this.jasperFile = jasperFile;
}

public JasperReport getJasperReport() {
return jasperReport;
}

public File getReportDir() {
return reportDir;
}

public String getJasperName() {
return jasperName;
}

public File getJasperFile() {
return jasperFile;
}
}

class FileFilter implements FilenameFilter {
private String reportStart;
private File directory;
private String extension;

public FileFilter(String reportStart, File directory, String extension) {
this.reportStart = reportStart;
this.directory = directory;
this.extension = extension;
}

public boolean accept(File file, String name) {
if (file.equals( directory)) {
if (name.startsWith( reportStart)) {
int pos = name.lastIndexOf( extension);
if ( (pos!=-1) && (pos==(name.length()-extension.length()))) return true;
}
}
return false;
}
}

}
Fichiers attachés
Type de fichier : java RusReportStarter.java (15,5 Ko, 2 affichages)
kiki2000 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/10/2010, 13h29   #5
Invité de passage
 
Geoffrey Nimal
Inscription : septembre 2010
Messages : 10
Détails du profil
Informations personnelles :
Nom : Geoffrey Nimal

Informations forums :
Inscription : septembre 2010
Messages : 10
Points : 2
Points : 2
Putain ! Ce que ça peut me brouter les message sans suite*! Si tu as trouvé une solution, merci de la donner aux autres ; ou de spécifier un truc du genre [Ben, merde*! J’abandonne…]
Zenji est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h11.


 
 
 
 
Partenaires

Hébergement Web