Spring Web MVC - Spring Web Flow Working With JasperReports

Step 6: Other Beans Configuration

For this example we must configure the view resolver, url mapping, and some Web MVC beans. For that we must use springjasperreports-servlet.xml

<beans>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views"/>
</bean>

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="cacheSeconds" value="5"/>
<property name="basename" value="/WEB-INF/interproperties/messages"/>
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/welcome.htm">idWelcomeController</prop>
<prop key="/prereportsimplejasperreport.htm">idPreReportSimpleJasperReportController</prop>
<prop key="/reportsimplepdfjasperreport.htm">idReportSimplePdfJasperReportController</prop>
<prop key="/springwebflowjasperreports.htm">idSpringWebFlowJasperReportsFlowController</prop>
</props>
</property>
</bean>

<bean id="idWelcomeController"
class="com.springjasperreports.controler.mvc.welcome.WelcomeController" />

<bean id="idPreReportSimpleJasperReportController"
class="com.springjasperreports.controler.mvc.jasperreports.PreReportSimpleJasperReportController" />


</beans>

 

The bean declarations are clear by themselves. You should notice the two last beans idWelcomeController and idPreReportSimpleJasperReportController. They are two simple controllers that extend the super class AbstractController, both used for forward purposes.

Step 7: views.properties

All our views (jsp/pdf) must be configured in views.properties, for this, see below

welcome.(class) = org.springframework.web.servlet.view.JstlView
welcome.url = /WEB-INF/jsp/inicio.jsp

prereportsimplejasperreport.(class) = org.springframework.web.servlet.view.JstlView
prereportsimplejasperreport.url = /WEB-INF/jsp/mvc/reportSimpleJasperReport.jsp

springwebflowjasperreports-stepone.(class) = org.springframework.web.servlet.view.JstlView
springwebflowjasperreports-stepone.url = /WEB-INF/jsp/flow/swfjr-stepone.jsp

springwebflowjasperreports-steptwo.(class) = org.springframework.web.servlet.view.JstlView
springwebflowjasperreports-steptwo.url = /WEB-INF/jsp/flow/swfjr-steptwo.jsp

reportsimplepdfjasperreport.(class) = org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView
reportsimplepdfjasperreport.reportDataKey = datasource
reportsimplepdfjasperreport.url = /WEB-INF/reports/SpringJasperReportsspring.jasper

 

The most important part is for the Pdf View used by:

  • ReportSimplePdfJasperReportController class
  • springwebflowjasperreports-printpdf view-state
These consists of three parts:
  • The first our spring package to generate the pdf view
  • The second and in some way the trick part related with the jRBeanCollectionDataSource, the content of our report. If you see your Controller/Action classes the keyword datasource is used in both to assign the report:
    • parameterMap.put("datasource", jRBeanCollectionDataSource); in ReportSimplePdfJasperReportController class
    • context.getRequestScope().put("datasource", jRBeanCollectionDataSource); in ReportSimplePdfJasperReportAction class
    However "datasource" is sent to the SpringJasperReportsspring.jasper file.
  • The third part is the location of our SpringJasperReportsspring.jasper

 

Article Type: 
How-to
0
Average: 4 (1 vote)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

clermont38 replied on Fri, 2009/05/15 - 12:18pm

Is there source code for this?

cnbaluramesh replied on Sat, 2009/06/13 - 4:03am

Very interesting article. Where is the code ?

vijayasaradhi_p replied on Tue, 2009/08/18 - 10:56pm

This is very good article.. where can I get the Source code?

rajesh_dzone replied on Sun, 2009/09/27 - 9:47pm

The article is gud ..can i get the source code

zizul replied on Fri, 2009/11/13 - 5:24am

Helpful article, any chances to get a source code ?

Manuel Jordan replied on Sat, 2009/11/14 - 10:23pm

Hello Guys

 

The source is almost available.

My hard disk crushed months ago, and the source code is somewhere among many DVD,

Regards

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.