Listing 8-45.Specifying a Report Data Key for the Jasper Report
home.class=org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView
home.reportDataKey=jasperData
home.url=/WEB-INF/jasper/home.jrxml
In Listing 8-46, the Controllerreturns a model consisting of multiple objects, one of
which is keyed under the name specified as the report data key in the View.
Listing 8-46.A Model Containing the Report Data and Other Attributes
public ModelAndView handleReport(
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Map model = new HashMap();
Collection reportData = getReportData();
Collection otherData = getOtherData();
model.put("jasperData", reportData);
model.put("otherData", otherData);
return new ModelAndView("home", model);
}
Summary
Jasper is another very flexible view technology that has myriad options not explored in this
brief introduction. We’ve covered the basics of how to set up a JasperReport as a view and
expose your data to it. We strongly recommend that you visit the JasperReports website to get
a full rundown on what Jasper can do, safe in the knowledge that you can now apply all those
great features to your Spring MVC applications.
Creating New Views
That pretty much concludes our tour of supported view technologies in Spring applications—
and there was a lot of information to cover and take in. But what do you do in the unlikely
event that Spring has no first-class support for your favorite view technology? Write it yourself,
of course!
Spring is highly extensible in all departments, designed with thought in mind for the
cases where additional support might be required for fringe cases. The view layer is no differ-
ent.
If you need to implement a new view type, look through the JavaDoc and the source code
to see if one of the existing hierarchy of classes offers suitable functionality first. AbstractView
and AbstractUrlBasedVieware prime candidates.
Should those classes really not do anything that you need, then implement the Viewinter-
face directly and handle the response from the render()method.
CHAPTER 8 ■SUPPORTED VIEW TYPES 263