Using Views in the Sample Application

The SpringBlog sample application uses the Tiles framework extensively. We also implement an Excel view in SpringBlog to allow the users to download the Excel spreadsheet version of all blog entries. The sources for the tiles are JSP pages and there is also static content that does not need to be served by the web container.

The directory structure shown in Figure 18-9 explains the situation better: the /web/src/ as-web/WEB-INF directory contains files that are served and processed by the web container, whereas the /web/src/httpd-web contains files that can be served by the web server. Finally, the /web/src/resources folder contains the various properties and additional configuration files.

image from book
Figure 18-9: Directory structure of the web component of the sample application

We believe that this directory structure is the best way to organize files you need for the Web Tier of an application. The Ant build script packages the files into a WAR file, keeping the directory structure shown in Figure 18-9. The only exception is the resources directory. All files from this directory are packaged to WEB-INF/classes directory.

Let's take a closer look at the files we needed to create to successfully implement the various views used in the Web Tier of the application.

resources/messages.properties: This is the default message source file. If no localized messages_<LID>.properties is found, the messageSource bean falls back to using this file.

resources/messages_cs.properties: This is the Czech translation of the messages used in the messageSource bean.

resources/tiles-config.xml: This is the Tiles layout file. The contents of this file follow the rules outlined in the "Using Tiles" section.

resources/views.properties: This is the configuration file the ResourceBundleViewResolver uses to allow Spring to create instances of the View implementations using only the view name in the ModelAndView constructor.

views/**.jsp: These are standard JSP tile pages. This means that the JSPs contain the standard HTML tags. The only file that starts with the <HTML> tag is the views/tiles/ root-layout.jsp, which represents the root tile layout.

To demonstrate other view technologies, in the SpringBlog application, we included the Excel view that allows the users to download all entries in an Excel spreadsheet. The implementation of this view is simply an extension of the view we introduced in the "Using Excel Views" section.

We encourage you to go through the source tree yourselves, focusing on the naming conventions used for the view names, JSP pages, and Tile names. We believe that it is very important to have a clearly defined naming strategy, even for such small projects as SpringBlog.



Pro Spring
Pro Spring
ISBN: 1590594614
EAN: 2147483647
Year: 2006
Pages: 189

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net