Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Apache Geronimo and the Spring Framework, Part 6: Spring MVC: Using Web view technologies

Arun Chhatpar (arunchhatpar@gmail.com), Software Architect, OmniViz
Arun Chhatpar has more than nine years of significant experience in Java programming and client/server architectures, and is a Sun Certified Enterprise Software Architect. He has been a lead designer and developer for NBCi and is currently a software architect and lead software engineer for OmniViz.

Summary:  This tutorial, the final installment in a six-part series, shows you how to use JavaServer Pages (JSP), Velocity, Tiles, and PDF export using the Spring Framework. You'll experiment with the V in Model-View-Controller (MVC) — the various Web views built into the Spring MVC. Along with this solid introduction to the various view technologies supported by the Spring MVC, you'll see how easy these technologies are to implement in the sample Phonebook application you've been building throughout this series.

View more content in this series

Date:  23 Jan 2007
Level:  Intermediate PDF:  A4 and Letter (431 KB | 30 pages)Get Adobe® Reader®

Activity:  9925 views
Comments:  

Before you start

This tutorial series is for Java™ Platform, Enterprise Edition (Java EE) developers who want to learn more about the Spring Framework and how to make use of its powerful features on the Apache Geronimo application server.

About this series

This six-part tutorial series introduces you to the Spring Framework and how it fits in with Geronimo. You began by examining the different Spring Framework methodologies and how each works with the Geronimo server. You'll develop and deploy a personal phonebook application throughout the series. The application will include the following functionality:

  • Showing the phonebook
  • Showing details of each entry
  • Adding new entries to the phonebook
  • Editing, modifying, and deleting an entry
  • Adding more details to the entry, such as primary e-mail addresses

Part 1 introduces each module of the Spring Framework and how each relates to the development of Java EE applications on the Geronimo application server. It also explains the methodologies that the Spring Framework is based on.

Part 2 covers how to build your first bare-bones application using the Spring Framework on Geronimo.

Part 3 shows how to extend the Geronimo application from Part 2 by adding Java Database Connectivity (JDBC) support via the Derby database. In it, you see how to integrate Object Relational Mapping (ORM) to your application using iBATIS.

Part 4 introduces Spring AOP and the Spring Web Framework. With the Spring AOP, any object managed by the Spring Framework can become aspect oriented, and this tutorial relies on the declarative transaction management services provided via the Spring AOP.

Part 5 examines Spring MVC and gets you started with the Spring MVC by introducing its MVC framework and Web views.

This final installment, Part 6, shows you how to use JSP, Velocity, Tiles, and PDF export using the Spring Framework. You get to experiment with various Web views built into the Spring MVC.


About this tutorial

As mentioned, Part 5 of this tutorial series provides a thorough introduction to the Spring MVC module. You learned about different controllers offered by the Spring MVC — the C from MVC. This tutorial examines different view technologies — the V from MVC.

One of the biggest challenges that Web application developers face is creating an adaptable design. Making your views component flexible is particularly challenging. Because Spring's support for views is so robust, this challenge is more manageable. The use of JSPs, Tiles, Velocity, and PDF export in this tutorial is designed to demonstrate how the Spring MVC API makes this possible.

JSPs and Velocity are two complementary view technologies. You can create views using either one, each with its own set of advantages and disadvantages. This tutorial demonstrates how easy it is to replace one with the other in the sample Phonebook application.

You begin by reviewing JSP support in Spring MVC and then looking at Tiles, a very good templating engine for view layout management. Tiles makes it easy to manage your Web page layout, and Spring has built-in support for Tiles. You'll make use of these classes to change the Web layout of the Phonebook application.

Next you'll replace the use of JSPs by using views defined with the Velocity templating engine. Velocity makes it easy to access Java objects in your views without complex definitions and Java constructs, such as Try Catch loops.

Finally, you get a look at rendering the Phonebook application's home page to be displayed as a PDF file. Spring takes care of all the cumbersome and complex code and logic needed to create a PDF. It gives you a clean API to work on the content, without confusing you with PDF details.


Prerequisites

To follow along with this tutorial you should have a basic understanding of:

  • Object-oriented programming
  • Java Platform, Enterprise Edition (Java EE) terminology
  • SQL statements
  • XML semantics
  • JSP tags, tag libraries, and tag library descriptors

An understanding of MVC is a plus, and a working knowledge of Velocity is also highly advantageous, but isn't required.


System requirements

You need the following tools to follow along:

  • The Spring Framework V1.2.8 — You'll be using the compressed file with all dependencies.
  • Apache Geronimo V1.1 — Geronimo is a Java 2 Platform, Enterprise Edition (J2EE)-certified application server from Apache.
  • Apache Derby database — This tutorial uses Derby, which is an open source lightweight database. Derby is embedded within Geronimo 1.1, so no separate installations are required.
  • Velocity JAR files — You'll need the JAR files from the Velocity Template engine. You can either copy them form your Spring Framework installation or download it from the Velocity site.
  • iText — This is the PDF library used to generate PDFs on the fly. Spring uses this library to generate PDFs, and it's part of the Spring Framework.
  • Struts — This is the Tiles support from Spring that's dependent on the Struts API. You need the main struts.jar file from this API, which can be found in the Spring Framework.
  • Commons library JAR files needed by Spring Tiles support — You need commons-digester.jar, commons-collection.jar, and commons-beanutils.jar. These all come with the Spring Framework installation, so just copy them into your development environment.
  • Standard taglibs API — Because you'll be using JSP Standard Tag Library (JSTL) tags in your JSPs, you need the JAR files from this compressed file.
  • Standard JSTL library — The current release is 1.1.2.
  • Apache Ant — Make sure Ant is configured properly and that its /bin directory is in your Path system variable.
  • Java 1.4.2 — Make sure Java is installed and running on your system.

Install and configure the software

This section contains instructions for installing and configuring the software required to develop, deploy, and run the example application.

  1. Spring Framework and Geronimo installation: For the sample code to run, you need a working installation of both Geronimo and the Spring Framework. (Refer to Part 2 in this series for installation instructions.)
  2. JAR files needed to resolve Tiles dependencies: The following JAR files are needed by Tiles support in Spring:
    • Struts.jar — <SPRING_HOME>\lib\struts
    • Commons-digester.jar — <SPRING_HOME>\lib\jakarta-commons
    • Commons-collection-3.2.jar — <SPRING_HOME>\lib\jakarta-commons
    • Commons-beanutils.jar — <SPRING_HOME>\lib\jakarta-commons

    All of these JAR files come bundled with the Spring Framework installation package. You can find them in the directories indicated in the above list, next to the .jar file name. Make sure to copy all of these JAR files into the <WORKSPACE>/phonebook/lib directory.
  3. JAR files needed to resolve Velocity dependencies: The sample Phonebook application needs to include velocity-1.4.jar to work with Velocity. Velocity also needs the commons-collections.jar you copied for Tiles integration. The Velocity .jar file can be found in the Spring installation directory in <SPRING_HOME>\lib\velocity folder. Make sure to copy this into your <WORKSPACE>/phonebook/lib directory.
  4. JAR files needed to resolve PDF dependencies: Spring's PDF support API makes use of iText PDF library, so you need that for creating PDFs for your application. Like the other JAR files, this one also comes prepackaged with the Spring installation. You can find the itext-1.3.jar file in <SPRING_HOME>\lib\itext. Copy this in the lib directory as well.
  5. Installing Standard Taglibs from Apache and the Spring taglib: You'll use the JSPs defined in Part 5 of this tutorial series and extend your application using them, so you need to install JSTL libraries. (Refer to the installation instructions in Part 5 of this series.)
  6. Data model definition and database setup for your application: You'll use the same Derby database that you created in other parts of this tutorial series. The data model is also the same. If you created the database and tables in Part 3, 4, or 5, then you should be all set. If not, please follow instructions from Part 3 to take care of that first.

1 of 9 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Java technology, WebSphere
ArticleID=191788
TutorialTitle=Apache Geronimo and the Spring Framework, Part 6: Spring MVC: Using Web view technologies
publish-date=01232007
author1-email=arunchhatpar@gmail.com
author1-email-cc=ruterbo@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.