





















































A static view in a Spring Web MVC application is a view for which you don't explicitly create a controller class. We saw earlier that Spring Web MVC application scaffolded by Roo configures static views using element of Spring's mvc schema. The static views don't have an explicit controller, but behind the scenes Spring's built-in ParameterizableViewController is used for rendering static views. Here, we will look at web mvc install view command of Roo, which creates a static view.
Delete contents of ch04-recipe sub-directory inside C:roo-cookbook directory.
Copy ch04_web-app.roo script into ch04-recipe directory.
Execute ch04_web-app.roo script that creates flight-app Roo project, sets up Hibernate as persistence provider, configures MySQL as the database for the application, creates Flight and FlightDescription JPA entities and defines many-to-one relationship between Flight and FlightDescription entities. If you are using a different database than MySQL or your connection settings are different than what is specified in the script, then modify the script accordingly.
Start Roo shell from C:roo-cookbookch04-recipe directory.
Execute the controller all command to create controllers and views corresponding to JPA entities in flight-app project, as shown here:
.. roo> controller all --package ~.web
Execute perform eclipse command to update project's classpath settings, as shown here:
.. roo> perform eclipse
Now, import the flight-app project into your Eclipse IDE.
To add static views to a Roo-generated web application execute the web mvc install view command, as shown here:
.. roo> web mvc install view --path /static/views
--viewName help --title Help
The following table describes the arguments that web mvc install view command accepts:
Argument | Description |
path | Specifies the sub-folder inside /WEB-INF/views/ folder in which the view is created. |
viewName | The name of the view JSPX file. |
title | Specifies the name of the menu option with which the static view is accessible. |
As the output from the web mvc install view command suggests, following actions are taken by Spring Roo in response to executing the command:
<tiles-definitions>
<definition extends="default" name="static/views/help">
<put-attribute name="body"
value="/WEB-INF/views/static/views/help.jspx"/>
</definition>
</tiles-definitions>
<mvc:view-controller path="/static/view/help"/>