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
- 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
- The third part is the location of our SpringJasperReportsspring.jasper
- Login or register to post comments
- 29746 reads
- Printer-friendly version
(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
cnbaluramesh replied on Sat, 2009/06/13 - 4:03am
vijayasaradhi_p replied on Tue, 2009/08/18 - 10:56pm
rajesh_dzone replied on Sun, 2009/09/27 - 9:47pm
zizul replied on Fri, 2009/11/13 - 5:24am
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