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??

Reply via email to