You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by daniel ccss <da...@gmail.com> on 2008/01/02 21:31:21 UTC

JSF + JasperReports Problem

Hi all, I`m using JSF and JasperReports

All works fine, i mean no error is launch, but when the pdf was generated
and I opened it with Adobe I couldn`t open it. Then I opened it with textpad
and I saw that the pdf have the code of the jsp!!!!

*This is my code *(cuposAsignados is the arrayListthat contains the objects
that will be showing in the pdf report, and the class CuposAsignadosJasper
is the class that implements JRDataSource, in this case the report no
recived parameters)*:*

****************************************************************************************
This is the *Backing* *Bean Class* that create the report:

FacesContext facesContext = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext)
facesContext.getExternalContext().getContext();

File reportFile = new
File(servletContext.getRealPath("/reportes/cuposAsignados.jasper"));

InputStream reporte = new FileInputStream(reportFile);
*CuposAsignadosJasper* cuposAsignadosJasper =  new
*CuposAsignadosJasper*(cuposAsignados);

HashMap param = new HashMap();
JasperPrint jp = JasperFillManager.fillReport(reporte, param,
cuposAsignadosJasper);
byte[] bytes = JasperExportManager.exportReportToPdf(jp);

HttpServletResponse response = (HttpServletResponse)
facesContext.getExternalContext().getResponse();
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;filename=\"
cuposAsignados.pdf\"");
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.close();

****************************************************************************************
This is the class *CuposAsignadosJasper*
**
public class CuposAsignadosJasper implements JRDataSource{
    private Iterator iterator;
    private Cupo cupo;

   public Object *getFieldValue*(JRField arg0) throws JRException {
        if ("conCupo".equals(arg0.getName()))
            return String.valueOf(cupo.getConCupo());
        else if ("fecCupo".equals(arg0.getName()))
            return cupo.getFecCupo().toUpperCase();
        else if ("horaCompleta".equals(arg0.getName()))
            return cupo.getHoraCompleta().toUpperCase();
        return 0;
    }
    public boolean next() throws JRException {
        if (iterator.hasNext()) {
            cupo = (Cupo)iterator.next();
            return true;
        } else
            return false;
    }
    public CuposAsignadosJasper(ArrayList<Cupo> cuposAsignados) {
        iterator = cuposAsignados.listIterator();
    }
}
****************************************************************************************

All works fine but what the generated pdf have is the JSP code that create
it, is very strange, can anyone help me??

Re: JSF + JasperReports Problem

Posted by daniel ccss <da...@gmail.com>.
There is a PdfCopyFields class for JSF, in which jar.

On Jan 18, 2008 11:20 AM, Robert Stokes <rs...@fs.fed.us> wrote:

> Have you tried passing the OutputStream from the response to the
> PdfCopyFields instead of a FileOutputStream?
>
> Rob Stokes
>
> "daniel ccss" <da...@gmail.com> wrote on 01/18/2008 09:30:25 AM:
>
> > Anybody?
>
> > On Jan 18, 2008 7:59 AM, daniel ccss <da...@gmail.com> wrote:
> > Hi all, I have another question
> >
> > In Struts I do this for join 2 jasperreport pdfs:
> >
> > PdfReader reader1 = new PdfReader(bytes);
> > PdfReader reader2 = new PdfReader(bytes2);
> >
> > PdfCopyFields copy =
> > new PdfCopyFields(new FileOutputStream( context.
> > getRealPath("/reportes/Calificación de Derechos por Beneficio
> > Familiar - Resolución Nº " +
> > beneficioForm.getNumeroResolucionBeneficio() + ".pdf")));
> >
> > copy.addDocument(reader1);
> > copy.addDocument(reader2);
> > copy.close();
> >
> >
> > How can I do that with JSF, thanks!!
> >
> >
> >
> >
>
> > On Jan 2, 2008 3:36 PM, daniel ccss < danielccss2@gmail.com > wrote:
> > THANKS!!!
> >
> > I used the JRPdfExporter and the context.responseComplete(); and all
> > works for me :)
> >
> > Thanks again!!! :)
>
> > On Jan 2, 2008 10:18 PM, Robert Stokes <rs...@fs.fed.us> wrote:
> > Here is the method I use to create a PDF from Jasper reports, one think
> > that might be missing is the call to responseComplete().
> >
> >   private void exportPdfReport(InputStream reportInputStream, String
> > filename)
> >   {
> >      try
> >      {
> >         Map parameters = createParams();
> >         Connection connection = getCurrentConnection();
> >         JasperPrint jasperPrint =
> > JasperFillManager.fillReport(reportInputStream, parameters, connection);
> >         FacesContext context = FacesContext.getCurrentInstance();
> >         HttpServletResponse response = (HttpServletResponse)
> > context.getExternalContext().getResponse();
> >         response.setContentType("application/pdf");
> >         response.setHeader("Content-disposition", "Attachment;
> filename="
>
> > + filename + ".pdf");
> >         OutputStream outputStream = response.getOutputStream();
> >         JRPdfExporter exporterPdf = new JRPdfExporter();
> >         exporterPdf.setParameter(JRPdfExporterParameter.JASPER_PRINT ,
> > jasperPrint);
> >         exporterPdf.setParameter(JRPdfExporterParameter.OUTPUT_STREAM,
> > outputStream);
> >         exporterPdf.exportReport();
> >         connection.close();
> >         context.responseComplete();
> >      }
> >
> > Hope this helps
> >
> > Rob
> >
> >
> >
> > "daniel ccss" <da...@gmail.com> wrote on 01/02/2008 01:31:21 PM:
> >
> > > Hi all, I`m using JSF and JasperReports
> > >
> > > All works fine, i mean no error is launch, but when the pdf was
> > > generated and I opened it with Adobe I couldn`t open it. Then I
> > > opened it with textpad and I saw that the pdf have the code of the
> > jsp!!!!
> > >
> > > This is my code (cuposAsignados is the arrayListthat contains the
> > > objects that will be showing in the pdf report, and the class
> > > CuposAsignadosJasper is the class that implements JRDataSource, in
> > > this case the report no recived parameters) :
> > >
> > >
> >
>
> ****************************************************************************************
>
> > > This is the Backing Bean Class that create the report:
> > >
> > > FacesContext facesContext = FacesContext.getCurrentInstance();
> > > ServletContext servletContext = (ServletContext) facesContext.
> > > getExternalContext().getContext();
> > > File reportFile = new File(servletContext.
> > > getRealPath("/reportes/cuposAsignados.jasper"));
> > > InputStream reporte = new FileInputStream(reportFile);
> > > CuposAsignadosJasper cuposAsignadosJasper =  new CuposAsignadosJasper
> > > (cuposAsignados);
> > > HashMap param = new HashMap();
> > > JasperPrint jp = JasperFillManager.fillReport(reporte, param,
> > > cuposAsignadosJasper);
> > > byte[] bytes = JasperExportManager.exportReportToPdf (jp);
> > >
> > > HttpServletResponse response = (HttpServletResponse) facesContext.
> > > getExternalContext().getResponse();
> > > response.setContentType("application/pdf");
> > > response.setHeader ("Content-disposition", "attachment;
> > > filename=\"cuposAsignados.pdf\"");
> > > ServletOutputStream ouputStream = response.getOutputStream();
> > > ouputStream.write(bytes, 0, bytes.length );
> > > ouputStream.close();
> > >
> > >
> >
>
> ****************************************************************************************
>
> > > This is the class CuposAsignadosJasper
> > >
> > > public class CuposAsignadosJasper implements JRDataSource{
> > >     private Iterator iterator;
> > >     private Cupo cupo;
> > >
> > >    public Object getFieldValue(JRField arg0) throws JRException {
> > >         if ("conCupo".equals(arg0.getName()))
> > >             return String.valueOf(cupo.getConCupo());
> > >         else if ("fecCupo".equals(arg0.getName()))
> > >             return cupo.getFecCupo().toUpperCase();
> > >         else if ("horaCompleta".equals( arg0.getName()))
> > >             return cupo.getHoraCompleta().toUpperCase();
> > >         return 0;
> > >     }
> > >     public boolean next() throws JRException {
> > >         if (iterator.hasNext()) {
> > >             cupo = (Cupo)iterator.next();
> > >             return true;
> > >         } else
> > >             return false;
> > >     }
> > >     public CuposAsignadosJasper(ArrayList<Cupo> cuposAsignados) {
> > >         iterator = cuposAsignados.listIterator();
> > >     }
> > > }
> > >
> >
>
> ****************************************************************************************
>
> > >
> > > All works fine but what the generated pdf have is the JSP code that
> > > create it, is very strange, can anyone help me??
>
>

Re: JSF + JasperReports Problem

Posted by Robert Stokes <rs...@fs.fed.us>.
Have you tried passing the OutputStream from the response to the
PdfCopyFields instead of a FileOutputStream?

Rob Stokes

"daniel ccss" <da...@gmail.com> wrote on 01/18/2008 09:30:25 AM:

> Anybody?

> On Jan 18, 2008 7:59 AM, daniel ccss <da...@gmail.com> wrote:
> Hi all, I have another question
>
> In Struts I do this for join 2 jasperreport pdfs:
>
> PdfReader reader1 = new PdfReader(bytes);
> PdfReader reader2 = new PdfReader(bytes2);
>
> PdfCopyFields copy =
> new PdfCopyFields(new FileOutputStream( context.
> getRealPath("/reportes/Calificación de Derechos por Beneficio
> Familiar - Resolución Nº " +
> beneficioForm.getNumeroResolucionBeneficio() + ".pdf")));
>
> copy.addDocument(reader1);
> copy.addDocument(reader2);
> copy.close();
>
>
> How can I do that with JSF, thanks!!
>
>
>
>

> On Jan 2, 2008 3:36 PM, daniel ccss < danielccss2@gmail.com > wrote:
> THANKS!!!
>
> I used the JRPdfExporter and the context.responseComplete(); and all
> works for me :)
>
> Thanks again!!! :)

> On Jan 2, 2008 10:18 PM, Robert Stokes <rs...@fs.fed.us> wrote:
> Here is the method I use to create a PDF from Jasper reports, one think
> that might be missing is the call to responseComplete().
>
>   private void exportPdfReport(InputStream reportInputStream, String
> filename)
>   {
>      try
>      {
>         Map parameters = createParams();
>         Connection connection = getCurrentConnection();
>         JasperPrint jasperPrint =
> JasperFillManager.fillReport(reportInputStream, parameters, connection);
>         FacesContext context = FacesContext.getCurrentInstance();
>         HttpServletResponse response = (HttpServletResponse)
> context.getExternalContext().getResponse();
>         response.setContentType("application/pdf");
>         response.setHeader("Content-disposition", "Attachment; filename="

> + filename + ".pdf");
>         OutputStream outputStream = response.getOutputStream();
>         JRPdfExporter exporterPdf = new JRPdfExporter();
>         exporterPdf.setParameter(JRPdfExporterParameter.JASPER_PRINT ,
> jasperPrint);
>         exporterPdf.setParameter(JRPdfExporterParameter.OUTPUT_STREAM,
> outputStream);
>         exporterPdf.exportReport();
>         connection.close();
>         context.responseComplete();
>      }
>
> Hope this helps
>
> Rob
>
>
>
> "daniel ccss" <da...@gmail.com> wrote on 01/02/2008 01:31:21 PM:
>
> > Hi all, I`m using JSF and JasperReports
> >
> > All works fine, i mean no error is launch, but when the pdf was
> > generated and I opened it with Adobe I couldn`t open it. Then I
> > opened it with textpad and I saw that the pdf have the code of the
> jsp!!!!
> >
> > This is my code (cuposAsignados is the arrayListthat contains the
> > objects that will be showing in the pdf report, and the class
> > CuposAsignadosJasper is the class that implements JRDataSource, in
> > this case the report no recived parameters) :
> >
> >
>
****************************************************************************************

> > This is the Backing Bean Class that create the report:
> >
> > FacesContext facesContext = FacesContext.getCurrentInstance();
> > ServletContext servletContext = (ServletContext) facesContext.
> > getExternalContext().getContext();
> > File reportFile = new File(servletContext.
> > getRealPath("/reportes/cuposAsignados.jasper"));
> > InputStream reporte = new FileInputStream(reportFile);
> > CuposAsignadosJasper cuposAsignadosJasper =  new CuposAsignadosJasper
> > (cuposAsignados);
> > HashMap param = new HashMap();
> > JasperPrint jp = JasperFillManager.fillReport(reporte, param,
> > cuposAsignadosJasper);
> > byte[] bytes = JasperExportManager.exportReportToPdf (jp);
> >
> > HttpServletResponse response = (HttpServletResponse) facesContext.
> > getExternalContext().getResponse();
> > response.setContentType("application/pdf");
> > response.setHeader ("Content-disposition", "attachment;
> > filename=\"cuposAsignados.pdf\"");
> > ServletOutputStream ouputStream = response.getOutputStream();
> > ouputStream.write(bytes, 0, bytes.length );
> > ouputStream.close();
> >
> >
>
****************************************************************************************

> > This is the class CuposAsignadosJasper
> >
> > public class CuposAsignadosJasper implements JRDataSource{
> >     private Iterator iterator;
> >     private Cupo cupo;
> >
> >    public Object getFieldValue(JRField arg0) throws JRException {
> >         if ("conCupo".equals(arg0.getName()))
> >             return String.valueOf(cupo.getConCupo());
> >         else if ("fecCupo".equals(arg0.getName()))
> >             return cupo.getFecCupo().toUpperCase();
> >         else if ("horaCompleta".equals( arg0.getName()))
> >             return cupo.getHoraCompleta().toUpperCase();
> >         return 0;
> >     }
> >     public boolean next() throws JRException {
> >         if (iterator.hasNext()) {
> >             cupo = (Cupo)iterator.next();
> >             return true;
> >         } else
> >             return false;
> >     }
> >     public CuposAsignadosJasper(ArrayList<Cupo> cuposAsignados) {
> >         iterator = cuposAsignados.listIterator();
> >     }
> > }
> >
>
****************************************************************************************

> >
> > All works fine but what the generated pdf have is the JSP code that
> > create it, is very strange, can anyone help me??


Re: JSF + JasperReports Problem

Posted by daniel ccss <da...@gmail.com>.
Anybody?

On Jan 18, 2008 7:59 AM, daniel ccss <da...@gmail.com> wrote:

> Hi all, I have another question
>
> In Struts I do this for join 2 jasperreport pdfs:
>
> PdfReader reader1 = new PdfReader(bytes);
> PdfReader reader2 = new PdfReader(bytes2);
>
> PdfCopyFields copy =
> new PdfCopyFields(new FileOutputStream( context.getRealPath("/reportes/Calificación
> de Derechos por Beneficio
> Familiar - Resolución Nº " +
> beneficioForm.getNumeroResolucionBeneficio() + ".pdf")));
>
> copy.addDocument(reader1);
> copy.addDocument(reader2);
> copy.close();
>
>
> How can I do that with JSF, thanks!!
>
>
>
>
>
> On Jan 2, 2008 3:36 PM, daniel ccss <danielccss2@gmail.com > wrote:
>
> > THANKS!!!
> >
> > I used the JRPdfExporter and the context.responseComplete(); and all
> > works for me :)
> >
> > Thanks again!!! :)
> >
> > On Jan 2, 2008 10:18 PM, Robert Stokes <rs...@fs.fed.us> wrote:
> >
> > > Here is the method I use to create a PDF from Jasper reports, one
> > > think
> > > that might be missing is the call to responseComplete().
> > >
> > >   private void exportPdfReport(InputStream reportInputStream, String
> > > filename)
> > >   {
> > >      try
> > >      {
> > >         Map parameters = createParams();
> > >         Connection connection = getCurrentConnection();
> > >         JasperPrint jasperPrint =
> > > JasperFillManager.fillReport(reportInputStream, parameters,
> > > connection);
> > >         FacesContext context = FacesContext.getCurrentInstance();
> > >         HttpServletResponse response = (HttpServletResponse)
> > > context.getExternalContext().getResponse();
> > >         response.setContentType("application/pdf");
> > >         response.setHeader("Content-disposition", "Attachment;
> > > filename="
> > > + filename + ".pdf");
> > >         OutputStream outputStream = response.getOutputStream();
> > >         JRPdfExporter exporterPdf = new JRPdfExporter();
> > >         exporterPdf.setParameter(JRPdfExporterParameter.JASPER_PRINT ,
> > > jasperPrint);
> > >         exporterPdf.setParameter(JRPdfExporterParameter.OUTPUT_STREAM,
> > > outputStream);
> > >         exporterPdf.exportReport();
> > >         connection.close();
> > >         context.responseComplete();
> > >      }
> > >
> > > Hope this helps
> > >
> > > Rob
> > >
> > >
> > >
> > > "daniel ccss" <da...@gmail.com> wrote on 01/02/2008 01:31:21 PM:
> > >
> > > > Hi all, I`m using JSF and JasperReports
> > > >
> > > > All works fine, i mean no error is launch, but when the pdf was
> > > > generated and I opened it with Adobe I couldn`t open it. Then I
> > > > opened it with textpad and I saw that the pdf have the code of the
> > > jsp!!!!
> > > >
> > > > This is my code (cuposAsignados is the arrayListthat contains the
> > > > objects that will be showing in the pdf report, and the class
> > > > CuposAsignadosJasper is the class that implements JRDataSource, in
> > > > this case the report no recived parameters) :
> > > >
> > > >
> > > ****************************************************************************************
> > >
> > > > This is the Backing Bean Class that create the report:
> > > >
> > > > FacesContext facesContext = FacesContext.getCurrentInstance();
> > > > ServletContext servletContext = (ServletContext) facesContext.
> > > > getExternalContext().getContext();
> > > > File reportFile = new File(servletContext.
> > > > getRealPath("/reportes/cuposAsignados.jasper"));
> > > > InputStream reporte = new FileInputStream(reportFile);
> > > > CuposAsignadosJasper cuposAsignadosJasper =  new
> > > CuposAsignadosJasper
> > > > (cuposAsignados);
> > > > HashMap param = new HashMap();
> > > > JasperPrint jp = JasperFillManager.fillReport(reporte, param,
> > > > cuposAsignadosJasper);
> > > > byte[] bytes = JasperExportManager.exportReportToPdf (jp);
> > > >
> > > > HttpServletResponse response = (HttpServletResponse) facesContext.
> > > > getExternalContext().getResponse();
> > > > response.setContentType("application/pdf");
> > > > response.setHeader ("Content-disposition", "attachment;
> > > > filename=\"cuposAsignados.pdf\"");
> > > > ServletOutputStream ouputStream = response.getOutputStream();
> > > > ouputStream.write(bytes, 0, bytes.length );
> > > > ouputStream.close();
> > > >
> > > >
> > >
> > > ****************************************************************************************
> > > > This is the class CuposAsignadosJasper
> > > >
> > > > public class CuposAsignadosJasper implements JRDataSource{
> > > >     private Iterator iterator;
> > > >     private Cupo cupo;
> > > >
> > > >    public Object getFieldValue(JRField arg0) throws JRException {
> > > >         if ("conCupo".equals(arg0.getName()))
> > > >             return String.valueOf(cupo.getConCupo());
> > > >         else if ("fecCupo".equals(arg0.getName()))
> > > >             return cupo.getFecCupo().toUpperCase();
> > > >         else if ("horaCompleta".equals( arg0.getName()))
> > > >             return cupo.getHoraCompleta().toUpperCase();
> > > >         return 0;
> > > >     }
> > > >     public boolean next() throws JRException {
> > > >         if (iterator.hasNext()) {
> > > >             cupo = (Cupo)iterator.next();
> > > >             return true;
> > > >         } else
> > > >             return false;
> > > >     }
> > > >     public CuposAsignadosJasper(ArrayList<Cupo> cuposAsignados) {
> > > >         iterator = cuposAsignados.listIterator();
> > > >     }
> > > > }
> > > >
> > >
> > > ****************************************************************************************
> > > >
> > > > All works fine but what the generated pdf have is the JSP code that
> > > > create it, is very strange, can anyone help me??
> > >
> > >
> >
>

Re: JSF + JasperReports Problem

Posted by daniel ccss <da...@gmail.com>.
Hi all, I have another question

In Struts I do this for join 2 jasperreport pdfs:

PdfReader reader1 = new PdfReader(bytes);
PdfReader reader2 = new PdfReader(bytes2);

PdfCopyFields copy =
new PdfCopyFields(new
FileOutputStream(context.getRealPath("/reportes/Calificación
de Derechos por Beneficio
Familiar - Resolución Nº " +
beneficioForm.getNumeroResolucionBeneficio() + ".pdf")));

copy.addDocument(reader1);
copy.addDocument(reader2);
copy.close();


How can I do that with JSF, thanks!!




On Jan 2, 2008 3:36 PM, daniel ccss <da...@gmail.com> wrote:

> THANKS!!!
>
> I used the JRPdfExporter and the context.responseComplete(); and all works
> for me :)
>
> Thanks again!!! :)
>
> On Jan 2, 2008 10:18 PM, Robert Stokes <rs...@fs.fed.us> wrote:
>
> > Here is the method I use to create a PDF from Jasper reports, one think
> > that might be missing is the call to responseComplete().
> >
> >   private void exportPdfReport(InputStream reportInputStream, String
> > filename)
> >   {
> >      try
> >      {
> >         Map parameters = createParams();
> >         Connection connection = getCurrentConnection();
> >         JasperPrint jasperPrint =
> > JasperFillManager.fillReport(reportInputStream, parameters, connection);
> >         FacesContext context = FacesContext.getCurrentInstance();
> >         HttpServletResponse response = (HttpServletResponse)
> > context.getExternalContext().getResponse();
> >         response.setContentType("application/pdf");
> >         response.setHeader("Content-disposition", "Attachment;
> > filename="
> > + filename + ".pdf");
> >         OutputStream outputStream = response.getOutputStream();
> >         JRPdfExporter exporterPdf = new JRPdfExporter();
> >         exporterPdf.setParameter(JRPdfExporterParameter.JASPER_PRINT ,
> > jasperPrint);
> >         exporterPdf.setParameter(JRPdfExporterParameter.OUTPUT_STREAM,
> > outputStream);
> >         exporterPdf.exportReport();
> >         connection.close();
> >         context.responseComplete();
> >      }
> >
> > Hope this helps
> >
> > Rob
> >
> >
> >
> > "daniel ccss" <da...@gmail.com> wrote on 01/02/2008 01:31:21 PM:
> >
> > > Hi all, I`m using JSF and JasperReports
> > >
> > > All works fine, i mean no error is launch, but when the pdf was
> > > generated and I opened it with Adobe I couldn`t open it. Then I
> > > opened it with textpad and I saw that the pdf have the code of the
> > jsp!!!!
> > >
> > > This is my code (cuposAsignados is the arrayListthat contains the
> > > objects that will be showing in the pdf report, and the class
> > > CuposAsignadosJasper is the class that implements JRDataSource, in
> > > this case the report no recived parameters) :
> > >
> > >
> > ****************************************************************************************
> >
> > > This is the Backing Bean Class that create the report:
> > >
> > > FacesContext facesContext = FacesContext.getCurrentInstance();
> > > ServletContext servletContext = (ServletContext) facesContext.
> > > getExternalContext().getContext();
> > > File reportFile = new File(servletContext.
> > > getRealPath("/reportes/cuposAsignados.jasper"));
> > > InputStream reporte = new FileInputStream(reportFile);
> > > CuposAsignadosJasper cuposAsignadosJasper =  new CuposAsignadosJasper
> > > (cuposAsignados);
> > > HashMap param = new HashMap();
> > > JasperPrint jp = JasperFillManager.fillReport(reporte, param,
> > > cuposAsignadosJasper);
> > > byte[] bytes = JasperExportManager.exportReportToPdf (jp);
> > >
> > > HttpServletResponse response = (HttpServletResponse) facesContext.
> > > getExternalContext().getResponse();
> > > response.setContentType("application/pdf");
> > > response.setHeader ("Content-disposition", "attachment;
> > > filename=\"cuposAsignados.pdf\"");
> > > ServletOutputStream ouputStream = response.getOutputStream();
> > > ouputStream.write(bytes, 0, bytes.length );
> > > ouputStream.close();
> > >
> > >
> >
> > ****************************************************************************************
> > > This is the class CuposAsignadosJasper
> > >
> > > public class CuposAsignadosJasper implements JRDataSource{
> > >     private Iterator iterator;
> > >     private Cupo cupo;
> > >
> > >    public Object getFieldValue(JRField arg0) throws JRException {
> > >         if ("conCupo".equals(arg0.getName()))
> > >             return String.valueOf(cupo.getConCupo());
> > >         else if ("fecCupo".equals(arg0.getName()))
> > >             return cupo.getFecCupo().toUpperCase();
> > >         else if ("horaCompleta".equals( arg0.getName()))
> > >             return cupo.getHoraCompleta().toUpperCase();
> > >         return 0;
> > >     }
> > >     public boolean next() throws JRException {
> > >         if (iterator.hasNext()) {
> > >             cupo = (Cupo)iterator.next();
> > >             return true;
> > >         } else
> > >             return false;
> > >     }
> > >     public CuposAsignadosJasper(ArrayList<Cupo> cuposAsignados) {
> > >         iterator = cuposAsignados.listIterator();
> > >     }
> > > }
> > >
> >
> > ****************************************************************************************
> > >
> > > All works fine but what the generated pdf have is the JSP code that
> > > create it, is very strange, can anyone help me??
> >
> >
>

Re: JSF + JasperReports Problem

Posted by daniel ccss <da...@gmail.com>.
THANKS!!!

I used the JRPdfExporter and the context.responseComplete(); and all works
for me :)

Thanks again!!! :)

On Jan 2, 2008 10:18 PM, Robert Stokes <rs...@fs.fed.us> wrote:

> Here is the method I use to create a PDF from Jasper reports, one think
> that might be missing is the call to responseComplete().
>
>   private void exportPdfReport(InputStream reportInputStream, String
> filename)
>   {
>      try
>      {
>         Map parameters = createParams();
>         Connection connection = getCurrentConnection();
>         JasperPrint jasperPrint =
> JasperFillManager.fillReport(reportInputStream, parameters, connection);
>         FacesContext context = FacesContext.getCurrentInstance();
>         HttpServletResponse response = (HttpServletResponse)
> context.getExternalContext().getResponse();
>         response.setContentType("application/pdf");
>         response.setHeader("Content-disposition", "Attachment; filename="
> + filename + ".pdf");
>         OutputStream outputStream = response.getOutputStream();
>         JRPdfExporter exporterPdf = new JRPdfExporter();
>         exporterPdf.setParameter(JRPdfExporterParameter.JASPER_PRINT,
> jasperPrint);
>         exporterPdf.setParameter(JRPdfExporterParameter.OUTPUT_STREAM,
> outputStream);
>         exporterPdf.exportReport();
>         connection.close();
>         context.responseComplete();
>      }
>
> Hope this helps
>
> Rob
>
>
>
> "daniel ccss" <da...@gmail.com> wrote on 01/02/2008 01:31:21 PM:
>
> > Hi all, I`m using JSF and JasperReports
> >
> > All works fine, i mean no error is launch, but when the pdf was
> > generated and I opened it with Adobe I couldn`t open it. Then I
> > opened it with textpad and I saw that the pdf have the code of the
> jsp!!!!
> >
> > This is my code (cuposAsignados is the arrayListthat contains the
> > objects that will be showing in the pdf report, and the class
> > CuposAsignadosJasper is the class that implements JRDataSource, in
> > this case the report no recived parameters) :
> >
> >
>
> ****************************************************************************************
> > This is the Backing Bean Class that create the report:
> >
> > FacesContext facesContext = FacesContext.getCurrentInstance();
> > ServletContext servletContext = (ServletContext) facesContext.
> > getExternalContext().getContext();
> > File reportFile = new File(servletContext.
> > getRealPath("/reportes/cuposAsignados.jasper"));
> > InputStream reporte = new FileInputStream(reportFile);
> > CuposAsignadosJasper cuposAsignadosJasper =  new CuposAsignadosJasper
> > (cuposAsignados);
> > HashMap param = new HashMap();
> > JasperPrint jp = JasperFillManager.fillReport(reporte, param,
> > cuposAsignadosJasper);
> > byte[] bytes = JasperExportManager.exportReportToPdf(jp);
> >
> > HttpServletResponse response = (HttpServletResponse) facesContext.
> > getExternalContext().getResponse();
> > response.setContentType("application/pdf");
> > response.setHeader("Content-disposition", "attachment;
> > filename=\"cuposAsignados.pdf\"");
> > ServletOutputStream ouputStream = response.getOutputStream();
> > ouputStream.write(bytes, 0, bytes.length);
> > ouputStream.close();
> >
> >
>
> ****************************************************************************************
> > This is the class CuposAsignadosJasper
> >
> > public class CuposAsignadosJasper implements JRDataSource{
> >     private Iterator iterator;
> >     private Cupo cupo;
> >
> >    public Object getFieldValue(JRField arg0) throws JRException {
> >         if ("conCupo".equals(arg0.getName()))
> >             return String.valueOf(cupo.getConCupo());
> >         else if ("fecCupo".equals(arg0.getName()))
> >             return cupo.getFecCupo().toUpperCase();
> >         else if ("horaCompleta".equals(arg0.getName()))
> >             return cupo.getHoraCompleta().toUpperCase();
> >         return 0;
> >     }
> >     public boolean next() throws JRException {
> >         if (iterator.hasNext()) {
> >             cupo = (Cupo)iterator.next();
> >             return true;
> >         } else
> >             return false;
> >     }
> >     public CuposAsignadosJasper(ArrayList<Cupo> cuposAsignados) {
> >         iterator = cuposAsignados.listIterator();
> >     }
> > }
> >
>
> ****************************************************************************************
> >
> > All works fine but what the generated pdf have is the JSP code that
> > create it, is very strange, can anyone help me??
>
>

Re: JSF + JasperReports Problem

Posted by Robert Stokes <rs...@fs.fed.us>.
Here is the method I use to create a PDF from Jasper reports, one think
that might be missing is the call to responseComplete().

   private void exportPdfReport(InputStream reportInputStream, String
filename)
   {
      try
      {
         Map parameters = createParams();
         Connection connection = getCurrentConnection();
         JasperPrint jasperPrint =
JasperFillManager.fillReport(reportInputStream, parameters, connection);
         FacesContext context = FacesContext.getCurrentInstance();
         HttpServletResponse response = (HttpServletResponse)
context.getExternalContext().getResponse();
         response.setContentType("application/pdf");
         response.setHeader("Content-disposition", "Attachment; filename="
+ filename + ".pdf");
         OutputStream outputStream = response.getOutputStream();
         JRPdfExporter exporterPdf = new JRPdfExporter();
         exporterPdf.setParameter(JRPdfExporterParameter.JASPER_PRINT,
jasperPrint);
         exporterPdf.setParameter(JRPdfExporterParameter.OUTPUT_STREAM,
outputStream);
         exporterPdf.exportReport();
         connection.close();
         context.responseComplete();
      }

Hope this helps

Rob



"daniel ccss" <da...@gmail.com> wrote on 01/02/2008 01:31:21 PM:

> Hi all, I`m using JSF and JasperReports
>
> All works fine, i mean no error is launch, but when the pdf was
> generated and I opened it with Adobe I couldn`t open it. Then I
> opened it with textpad and I saw that the pdf have the code of the
jsp!!!!
>
> This is my code (cuposAsignados is the arrayListthat contains the
> objects that will be showing in the pdf report, and the class
> CuposAsignadosJasper is the class that implements JRDataSource, in
> this case the report no recived parameters) :
>
>
****************************************************************************************
> This is the Backing Bean Class that create the report:
>
> FacesContext facesContext = FacesContext.getCurrentInstance();
> ServletContext servletContext = (ServletContext) facesContext.
> getExternalContext().getContext();
> File reportFile = new File(servletContext.
> getRealPath("/reportes/cuposAsignados.jasper"));
> InputStream reporte = new FileInputStream(reportFile);
> CuposAsignadosJasper cuposAsignadosJasper =  new CuposAsignadosJasper
> (cuposAsignados);
> HashMap param = new HashMap();
> JasperPrint jp = JasperFillManager.fillReport(reporte, param,
> cuposAsignadosJasper);
> byte[] bytes = JasperExportManager.exportReportToPdf(jp);
>
> HttpServletResponse response = (HttpServletResponse) facesContext.
> getExternalContext().getResponse();
> response.setContentType("application/pdf");
> response.setHeader("Content-disposition", "attachment;
> filename=\"cuposAsignados.pdf\"");
> ServletOutputStream ouputStream = response.getOutputStream();
> ouputStream.write(bytes, 0, bytes.length);
> ouputStream.close();
>
>
****************************************************************************************
> This is the class CuposAsignadosJasper
>
> public class CuposAsignadosJasper implements JRDataSource{
>     private Iterator iterator;
>     private Cupo cupo;
>
>    public Object getFieldValue(JRField arg0) throws JRException {
>         if ("conCupo".equals(arg0.getName()))
>             return String.valueOf(cupo.getConCupo());
>         else if ("fecCupo".equals(arg0.getName()))
>             return cupo.getFecCupo().toUpperCase();
>         else if ("horaCompleta".equals(arg0.getName()))
>             return cupo.getHoraCompleta().toUpperCase();
>         return 0;
>     }
>     public boolean next() throws JRException {
>         if (iterator.hasNext()) {
>             cupo = (Cupo)iterator.next();
>             return true;
>         } else
>             return false;
>     }
>     public CuposAsignadosJasper(ArrayList<Cupo> cuposAsignados) {
>         iterator = cuposAsignados.listIterator();
>     }
> }
>
****************************************************************************************
>
> All works fine but what the generated pdf have is the JSP code that
> create it, is very strange, can anyone help me??