KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > mvc > ParameterizableViewController


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.servlet.mvc;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21
22 import org.springframework.web.servlet.ModelAndView;
23
24 /**
25  * <p>Trivial controller that always returns a named view. The view
26  * can be configured using an exposed configuration property. This
27  * controller offers an alternative to sending a request straight to a view
28  * such as a JSP. The advantage here is that the client is not exposed to
29  * the concrete view technology but rather just to the controller URL;
30  * the concrete view will be determined by the ViewResolver.
31  *
32  * <p>An alternative to the ParameterizableViewController is a
33  * {@link org.springframework.web.servlet.mvc.multiaction.MultiActionController MultiActionController},
34  * which can define a variety of handler methods that just return a plain
35  * ModelAndView instance for a given view name.
36  *
37  * <p><b><a name="workflow">Workflow
38  * (<a HREF="AbstractController.html#workflow">and that defined by superclass</a>):</b><br>
39  * <ol>
40  * <li>Request is received by the controller</li>
41  * <li>call to {@link #handleRequestInternal handleRequestInternal} which
42  * just returns the view, named by the configuration property
43  * <code>viewName</code>. Nothing more, nothing less</li>
44  * </ol>
45  * </p>
46  *
47  * <p><b><a name="config">Exposed configuration properties</a>
48  * (<a HREF="AbstractController.html#config">and those defined by superclass</a>):</b><br>
49  * <table border="1">
50  * <tr>
51  * <td><b>name</b></td>
52  * <td><b>default</b></td>
53  * <td><b>description</b></td>
54  * </tr>
55  * <tr>
56  * <td>viewName</td>
57  * <td><i>null</i></td>
58  * <td>the name of the view the viewResolver will use to forward to
59  * (if this property is not set, an exception will be thrown during
60  * initialization)</td>
61  * </tr>
62  * </table>
63  * </p>
64  *
65  * @author Rod Johnson
66  * @author Juergen Hoeller
67  */

68 public class ParameterizableViewController extends AbstractController {
69     
70     private String JavaDoc viewName;
71
72
73     /**
74      * Set the name of the view to delegate to.
75      */

76     public void setViewName(String JavaDoc viewName) {
77         this.viewName = viewName;
78     }
79
80     /**
81      * Return the name of the view to delegate to.
82      */

83     public String JavaDoc getViewName() {
84         return this.viewName;
85     }
86
87     protected void initApplicationContext() {
88         if (this.viewName == null) {
89             throw new IllegalArgumentException JavaDoc("Property 'viewName' is required");
90         }
91     }
92
93
94     /**
95      * Return a ModelAndView object with the specified view name.
96      * @see #getViewName()
97      */

98     protected ModelAndView handleRequestInternal(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
99             throws Exception JavaDoc {
100
101         return new ModelAndView(getViewName());
102     }
103
104 }
105
Popular Tags