JSC with jasper report
hello,
I developed the small web based application by using java studio creator in JSF. Now, i want to prepare the report by using jasper report.
so, i refer the following link
http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/ reports.html
but i didn't get the clear idea...(i cant understand the tags which is in TripReportByPerson.jrxml )
i download all the needed jar files which is mention in that page..
please let me know anybody or please refer me some other better tutorial..
Thanks,
# 1
That was actually a pretty detailed link, but for just the nuts and bolts, here are a
couple methods from an application that generates a Jasper report and creates a
PDF for viewing or saving to file.
The first method creates a JasperPrint object using a compiled report from iReports.
The second method creates a pdf formatted report from the JasperPrint object and
prompts the client for viewing or saving the pdf file.
The report itself was created using iReport and compiled to generate a Report.jasper file as input to the JasperFillManager.fillReport() method.
This uses Jasper Reports 1.3.2 libraries and seems to work fine.
Hope this helps.
// Create report
public boolean createIoReport()
{
JasperPrint jp=null;
JasperReport jr = null;
String s1 = getRptIoStart();
String s2 = getRptIoEnd();
if( !checkRptDateFields( s1, s2 ) )return false;
if( !hasStartDate )s1 = s2;
if( !hasEndDate )s2 = s1;
try
{
int k = Integer.parseInt( getSelectedDirection());
String title = "Inbound Report for " + s1;
if( !startDate.equals( endDate ))title = title + " to " + s2;
// Add report input parameters
Map parameters = new HashMap();
parameters.put( "p_inOut", new Integer(k) );
parameters.put( "p_start_date", startDate );
parameters.put( "p_end_date", endDate );
parameters.put( "p_title", title );
// Fill the report 'conn' is database connection
jp = JasperFillManager.fillReport( reportDir+"InOut_Report.jasper", parameters, conn );
// Create the PDF
doPdfReport( jp, "InboundReport" );
}
catch( Exception e )
{
log( "<SessionBean1.createIoReport> Error: "+ e.toString());
return false;
}
return true;
}
// Servlet part to display report in Adobe
public void doPdfReport( JasperPrint reportout, String filename )
{
byte[] pdf =null;
// Create the pdf formatted report stream
try {
pdf = JasperExportManager.exportReportToPdf(reportout);
}
catch (JRException ex3) {
error("Couldn't create PDF: "+ex3);
}
// Set up the servlet stuff
FacesContext faces = javax.faces.context.FacesContext.getCurrentInstance();
HttpServletResponse response =(HttpServletResponse)faces.getExternalContext().getResponse();
// Some additional setup parameters
response.setContentType("application/pdf");
response.setContentLength(pdf.length);
response.setHeader("Content-disposition","attachment; filename=\""+filename+".pdf\"");
ServletOutputStream out;
try{
// Send the report stream to the servlet
out = response.getOutputStream();
out.write(pdf);
}catch (Exception qw){
error("Could not output file:"+qw);
}
faces.responseComplete();
}
# 2
I made the assumption that you are using iReport to generate and test the report
rather than trying to create a .jrxml file by hand.
I forgot to add the imports you need
The top set is for the servlet and output stream stuff
The bottom set is for the jasper reports stuff.
You probably don't need import net.sf.jasperreports.view.*;
I think that is if you are using JasperViewer.
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import net.sf.jasperreports.engine.export.*;
import net.sf.jasperreports.engine.design.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.*;
# 3
sir i hava also same proble
sir i use ireport i designed fahim.jrxml and test in ireport JasperViewer
that show rihgt result
sir give me help in some point
1. how i ireport JasperViewer Configure with studio creater
2. how i pass parameter in ireport JasperViewer
3. how i call my fahim.jrxml from studio creater in ireport JasperViewer
some body give me some idea i use this code
JasperReport jasperReport = JasperCompileManager.compileReport("--Report file path-- .jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,new HashMap(),obj);
how i import jasperreports in java class
when i import your give these file
import net.sf.jasperreports.engine.export.*;
import net.sf.jasperreports.engine.design.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.*;
java class give me error
please give me idea and step how i call ireport JasperViewer in studio creater
thank's
aamir
# 4
sir i add jasperreports-1.3.3.jar file in project libraries and import these file
import net.sf.jasperreports.engine.export.*;
import net.sf.jasperreports.engine.design.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.*;
java no give error error
but when i call then system give me error
//JasperReport fahimaamir = JasperCompileManager.compileReport(sourceFileName);
JasperReport jasperReport = JasperCompileManager.compileReport("f:\ireport\fahim.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,new HashMap(),obj);
sir how i call my fahim.jrxml in ireport JasperViewer
please give me idea and code
thank's
aamir