Results 1 to 9 of 9

Thread: Problem with Jasper Reports support

  1. #1
    Join Date
    Oct 2004
    Location
    Havana, Cuba
    Posts
    25

    Default Problem with Jasper Reports support

    Hi,

    We have a problem developing a example to use the view classes that spring have to handle Jasper Reports, we read the documentation on version 1.1.3 and with that our example run without problem using resource bundled view resolver

    like that:

    Controller fragment

    Map model = new HashMap();
    model=getModel();
    return new ModelAndView("simpleReportPDFView", model);

    view resolver file fragment

    simpleReportPDFView.class=org.springframework.web. servlet.view.jasperreports.JasperReportsPdfView
    simpleReportPDFView.url=/WEB-INF/matriculas.jasper

    That work perfectly, Now if we want to instantiate the view object directily in the controller we get a null pointer exception, here we put the new code in the controller

    Controller fragment

    Map model = new HashMap();
    model=getModel();
    AbstractJasperReportsView view = new JasperReportsPdfView();
    return new ModelAndView(view, model);

    Error trace fragment

    java.lang.NullPointerException
    net.sf.jasperreports.engine.fill.JRFiller.fillRepo rt(JRFiller.java:142)
    net.sf.jasperreports.engine.JasperFillManager.fill Report(JasperFillManager.java:472)
    org.springframework.web.servlet.view.jasperreports .AbstractJasperReportsView.renderReport(AbstractJa sperReportsView.java:241)
    org.springframework.web.servlet.view.jasperreports .AbstractJasperReportsView.renderMergedOutputModel (AbstractJasperReportsView.java:165)
    org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:247)
    org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:784)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:621)
    org.springframework.web.servlet.FrameworkServlet.s erviceWrapper(FrameworkServlet.java:368)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:328)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
    net.sf.acegisecurity.intercept.web.FilterSecurityI nterceptor.proceedWithObject(FilterSecurityInterce ptor.java:87)
    net.sf.acegisecurity.intercept.AbstractSecurityInt erceptor.interceptor(AbstractSecurityInterceptor.j ava:368)
    net.sf.acegisecurity.intercept.web.FilterSecurityI nterceptor.invoke(FilterSecurityInterceptor.java:7 8)
    net.sf.acegisecurity.intercept.web.SecurityEnforce mentFilter.doFilter(SecurityEnforcementFilter.java :165)
    net.sf.acegisecurity.util.FilterToBeanProxy.doFilt er(FilterToBeanProxy.java:88)
    net.sf.acegisecurity.ui.AbstractIntegrationFilter. doFilter(AbstractIntegrationFilter.java:170)
    net.sf.acegisecurity.ui.basicauth.BasicProcessingF ilter.doFilter(BasicProcessingFilter.java:199)
    net.sf.acegisecurity.util.FilterToBeanProxy.doFilt er(FilterToBeanProxy.java:88)
    net.sf.acegisecurity.ui.AbstractProcessingFilter.d oFilter(AbstractProcessingFilter.java:368)
    net.sf.acegisecurity.util.FilterToBeanProxy.doFilt er(FilterToBeanProxy.java:88)


    Any Help will be preciated
    Regards Rodney and Silvia

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Rodney and Silvia,

    you need to provide the url of the report to be printed in the second case:
    Code:
    Map model = getModel(); 
    AbstractJasperReportsView view = new JasperReportsPdfView();
    view.setUrl("/WEB-INF/matriculas.jasper"); 
    return new ModelAndView(view, model);
    Personnaly I prefer the first approach.
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Oct 2004
    Location
    Havana, Cuba
    Posts
    25

    Default

    Sorry, we just forget to put the line in the second code in the topic we send that set the url of the view object the error ocurs with this line included, the first approach is a good solution but us want to add new reports from the user perspective adding the .jasper and configuring few tables in database without modify the views.properties file.

    Thanks for your interest
    Rodney and Silvia

  4. #4
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    You also need to inject the WebApplicationContext into the view:
    Code:
    Map model = getModel(); 
    AbstractJasperReportsView view = new JasperReportsPdfView(); 
    view.setUrl("/WEB-INF/matriculas.jasper"); 
    view.setApplicationContext(getApplicationContext());
    return new ModelAndView(view, model);
    applicationContext must be set after the url.
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  5. #5
    Join Date
    Oct 2004
    Location
    Havana, Cuba
    Posts
    25

    Default

    Thanks Omar, it works perfectly

    Regards Rodney

  6. #6
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Rodney,

    I'm interested to know what usecase you have for creating the view in the controller. Maybe I can integrate it into Spring with first class support.

    Rob

  7. #7
    Join Date
    Oct 2004
    Location
    Havana, Cuba
    Posts
    25

    Default

    Ok Rob, is a pleasure contribute Spring, the idea is using a Controller that extends SimpleFormController that show
    a View with the necessary parameters to run the report (there is one view for all the reports and the url parameter source distinguish between then) next with that parameters we run an HQL query (hibernate) that give to us a Set with the ojects to populate the report and with a custom implementation of JRDataSource we match the jasper params to object properties from the HQL report, then instanciate a View setting the url to obtain the .jasper and dispatch it.

    The idea is in an early stage but we want to create mechanism to define new reports its parameters and the HQL to obtain its data next upload the .jasper and made the system already list to run the new report, now in test stage we have the reports defined in an xml application context.

    If you want i can send you via email the classes we have implemented realted to that idea

    Best Regards
    Rodney
    Rodney Gallart
    Radikal Systems
    http://www.radikalsystems.com

  8. #8
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Rodney,

    Please, do send anything you come up with over to me if you are happy for it to be included in the codebase. I'll make sure you get author credits. The best way to send code is to post it in JIRA - that way all the devs have access to plus everyone can see what we are doing.

    Before you go to all the trouble - be aware that Spring will detect any implementation of JRDataSource that you place in the model and use that as the data source for the report, plus it will also pass any of the parameters in the model to JasperReports as report parameters. Maybe these features can help you to accomplish what you are doing.

    Rob

  9. #9
    Join Date
    Oct 2004
    Location
    Havana, Cuba
    Posts
    25

    Default

    Rob,

    We are using the functionality that you said about the detection of implementation of JRDataSource in the model, that's great, now i'm going to find the Spring JIRA and post the code (an early version) in the future we go to improve it and post it again.

    Rodney
    Rodney Gallart
    Radikal Systems
    http://www.radikalsystems.com

Similar Threads

  1. Problem with jasper reports integration
    By rodney.gallart in forum Web
    Replies: 0
    Last Post: Sep 19th, 2005, 02:03 PM
  2. Replies: 1
    Last Post: Sep 7th, 2005, 07:00 AM
  3. Replies: 1
    Last Post: Apr 10th, 2005, 01:26 PM
  4. Jasper Reports Thread Interruption
    By bhaarathm in forum EJB
    Replies: 4
    Last Post: Oct 5th, 2004, 12:03 PM
  5. Replies: 2
    Last Post: Oct 3rd, 2004, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •