Jump to content
We've recently updated our Privacy Statement, available here ×

Jasper java.lang.ClassCastException.


yazanki

Recommended Posts

I'm developing a new project JSF2.0 with MAVEN, PRIMEFACES, HIBERNATE and SPRING SECURITY WEB, when i try generate a report i get this error:

 

java.lang.ClassCastException: cannot assign instance of net.sf.jasperreports.engine.base.JRBaseTextField to field net.sf.jasperreports.engine.base.JRBaseParagraph.paragraphContainer of type net.sf.jasperreports.engine.JRParagraphContainer in instance of net.sf.jasperreports.engine.base.JRBaseParagraph

 

Any idea?

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

   try {

            FacesContext facesContext = FacesContext.getCurrentInstance();

            facesContext.responseComplete();

            ServletContext scontext = (ServletContext) facesContext.getExternalContext().getContext();

            JasperPrint jasperPrint = JasperFillManager.fillReport(scontext.getRealPath("/WEB-INF/reports/report.jasper"), parametros, new JRBeanCollectionDataSource(listaOler));

 

            ByteArrayOutputStream baos = new ByteArrayOutputStream();

 

            JRPdfExporter exporter = new JRPdfExporter();

            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

            exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);

            exporter.exportReport();

            byte[] bytes = baos.toByteArray();

 

            if (bytes != null && bytes.length > 0) {

                HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();

                response.setContentType("application/pdf");

                response.setHeader("Content-disposition", "inline; filename="olerite.pdf"");

                response.setContentLength(bytes.length);

                ServletOutputStream outputStream = response.getOutputStream();

                outputStream.write(bytes, 0, bytes.length);

                outputStream.flush();

                outputStream.close();

            }

        } catch (Exception e) {

            e.printStackTrace();

        }

Link to comment
Share on other sites

Hi,

The ClassCastException and the duplicate component warning indicate that you have two JasperReports jars on your classpath.Please check for the duplicate jars. If this is not the issue then youare probably using a Static Text field in your report where you need to be using a Text Field.

 

Hope that this helps

 

Thanks
Ankur Gupta

http://ankurthetechie.blogspot.in/

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...