View
- Layouts
- Extending layouts
- Generating views
- View files location
- Mapping views to urls
- Response format
- Handling response in different format
Layouts
Scooter uses sitemesh as a default layout mechanism.
Scooter supports both one-column layout and two-column layout as shown below:
![]() |
![]() |
To match a url pattern with a layout, you configure file webapps/your-web-app-name/WEB-INF/decorators.xml.
In order to use the two-column layout, you need to take out the comment line surrounding tag #sidemenu in webapps/your-web-app-name/static/stylesheets/main.css. The css tag allows you to put the side menu on either right hand side or left hand side of a screen.
Extending views
You can modify the layout files so that they fit into your own project need. For example, you may want to create a three-column layout view file. When you add a new layout file, make sure the layout file is registered in the decorators.xml file so that sitemesh can find it.
Generating views
Since views are associated with actions, Scooter's code generator creates one view for each action.
> java -jar tools/generate.jar blog controller posts index show
The about code generator will generate an index.jsp view and a show.jsp. Both are located under webapps/blog/WEB-INF/views/posts/ directory. You can then modify the views to fit into your requirements.
View files location
By default, all views are located under WEB-INF/views/{controller_name} directory.
If you want to put views in a different place, just change the webpage.directory.name property in config/environment.properties file.
Mapping views to urls
How views are located based on which processor is used in web.xml.
RestfulRequestProcessorThis is the default. When this processor is used, all incoming requests are matched with routes. Each route defines controller and action for the request.
For example,
url controller action view description ----------- --------------- ------ -------------------- ----------------------- GET /posts PostsController list() views/posts/list.jsp Display a list of posts GET /posts/2 PostsController show() views/posts/show.jsp Display details of a post with id 2BaseRequestProcessor
When this processor is used, urls of all incoming requests are compared with controller/view pattern.
For example,
url controller action view description ----------- --------------- ------ -------------------- ----------------------- /posts/list PostsController list() views/posts/list.jsp Display a list of posts /posts/show?id=2 PostsController show() views/posts/show.jsp Display details of a post with id 2
Default parameters
In either of the above two cases, it is possible that a controller does not exist or an action method does not exist. In these cases, Scooter uses the following two properties to direct further processing:
- allow.forward.to.controller.name.view.when.controller.not.exist
- allow.forward.to.action.name.view.when.action.not.exist
Both properties are in config/environment.properties file. Their default values are true.
By default, Scooter automatically picks up a view based on url of an incoming request without even requiring you to write a controller class or an action method.
Response format
Scooter can respond to request in many formats such as html, text, and xml, etc.. The default response format is html.
There are two ways to specify a response format.
1. Using url extensionScooter parses each request url. If your url ends with something like "*.{extension}", Scooter will check if "{extension}" is a valid extension. A valid extension has a corresponding Mime Type. All supported extensions and their associated mimetypes are in com/scooterframework/admin/extension_mimetypes.properties file. You can add additional extension/mimetype pairs by listing them in additional.mimetypes property in environment.properties.
/posts/1 => Client requests details of post with id 1. Scooter responds in html format. /posts/1.xml => Client requests details of post with id 1. Scooter responds in xml format. /users/John.Doe => Client requests details of user with name John Doe. Scooter responds in html format. /users/John.Doe.xml => Client requests details of user with name John Doe. Scooter responds in xml format.2. Using render() and renderView() methods
See details in Render a View.
Handling response in different format
What if you need to send response to caller by using a special format such as tax?
/users/John.Doe.tax => Client requests details of user with name John Doe. Scooter responds in tax format.
Scooter is flexible. See details in Content Handler on writing your own content handler.