We’ve outlined the behavior of AbstractXsltView, shown how to extend this class to pro-
vide your own concrete implementations, and looked at the case for nottransforming your
generated XML. You should now have enough knowledge to know not just how to apply XSL in
your Spring MVC applications, but when it is appropriate to consider it.
Next, we’re going to move on to some of the lesser-known and -used view technologies.
Spring offers PDF support via Bruno Lowagie’s iText library (http://www.lowagie.com/iText).
The basic premise follows the same pattern as that for XSLT support. For each view that you
wish to render as a PDF, you create a class that extends AbstractPdfViewand fill in the
required method buildPdfDocument().
Listing 8-39 shows an example that can be used to display the home page of our sample
application as a fairly simple PDF.
Listing 8-39.Creating the PDF from the Model
public class HomePagePdf extends AbstractPdfView {
@Override
protected void buildPdfDocument(
Map model,
Document document,
PdfWriter writer,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
Paragraph header = new Paragraph(new Chunk(
"FlightSearch Special Deals. ",
FontFactory.getFont(FontFactory.HELVETICA, 24)));
document.add(header);
List<SpecialDeal> specials = (List<SpecialDeal>) model.get("specials");
for (SpecialDeal deal : specials) {
document.add(new Paragraph(
deal.getDepartFrom().getName() + " - " +
deal.getArriveAt().getName() + " from $" +
deal.getCost()));
}
}
}
256 CHAPTER 8 ■SUPPORTED VIEW TYPES