|
Publicité ' | |||||||||||||||||||||||
|
|
#1 | ||
|
Invité de passage
![]() Inscription : janvier 2006 Messages : 6 ![]() |
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 :
|
||
|
|
00
|
|
|
#2 |
|
Invité de passage
![]() Inscription : janvier 2006 Messages : 6 ![]() |
slt,
personne n'as une idée sur mon probleme |
|
|
00
|
|
|
#3 |
|
Invité de passage
![]() Inscription : juin 2004 Messages : 3 ![]() |
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.
|
|
|
00
|
|
|
#4 |
|
Invité de passage
![]() Inscription : janvier 2006 Messages : 6 ![]() |
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; } } } |
|
|
00
|
|
|
#5 |
|
Invité de passage
![]() Geoffrey Nimal Inscription : septembre 2010 Messages : 10 ![]() |
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…]
|
|
|
00
|
Copyright © 2000-2012 - www.developpez.com