KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2006 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.portlet.mvc;
18
19 import javax.portlet.RenderRequest;
20 import javax.portlet.RenderResponse;
21
22 import org.springframework.web.portlet.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><b><a name="workflow">Workflow
33  * (<a HREF="AbstractController.html#workflow">and that defined by superclass</a>):</b><br>
34  * <ol>
35  * <li>Render request is received by the controller</li>
36  * <li>call to {@link #handleRenderRequestInternal handleRenderRequestInternal} which
37  * just returns the view, named by the configuration property
38  * <code>viewName</code>. Nothing more, nothing less</li>
39  * </ol>
40  * </p>
41  *
42  * <p>This controller does not handle action requests.</p>
43  *
44  * <p><b><a name="config">Exposed configuration properties</a>
45  * (<a HREF="AbstractController.html#config">and those defined by superclass</a>):</b><br>
46  * <table border="1">
47  * <tr>
48  * <td><b>name</b></td>
49  * <td><b>default</b></td>
50  * <td><b>description</b></td>
51  * </tr>
52  * <tr>
53  * <td>viewName</td>
54  * <td><i>null</i></td>
55  * <td>the name of the view the viewResolver will use to forward to
56  * (if this property is not set, an exception will be thrown during
57  * initialization)</td>
58  * </tr>
59  * </table>
60  * </p>
61  *
62  * @author John A. Lewis
63  * @since 2.0
64  */

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

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

80     public String JavaDoc getViewName() {
81         return viewName;
82     }
83
84     protected void initApplicationContext() {
85         if (this.viewName == null) {
86             throw new IllegalArgumentException JavaDoc("viewName is required");
87         }
88     }
89
90
91     /**
92      * Return a ModelAndView object with the specified view name.
93      */

94     protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response)
95             throws Exception JavaDoc {
96
97         return new ModelAndView(getViewName());
98     }
99
100 }
101
Popular Tags