Announcement Announcement Module
Collapse
No announcement yet.
Problem with Jasper Reports support Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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

      Comment


      • #4
        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

        Comment


        • #5
          Thanks Omar, it works perfectly

          Regards Rodney

          Comment


          • #6
            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

            Comment


            • #7
              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

              Comment


              • #8
                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

                Comment


                • #9
                  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

                  Comment

                  Working...
                  X