01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 viewName;
68:
69: /**
70: * Set the name of the view to delegate to.
71: */
72: public void setViewName(String viewName) {
73: this .viewName = viewName;
74: }
75:
76: /**
77: * Return the name of the view to delegate to.
78: */
79: public String getViewName() {
80: return viewName;
81: }
82:
83: protected void initApplicationContext() {
84: if (this .viewName == null) {
85: throw new IllegalArgumentException("viewName is required");
86: }
87: }
88:
89: /**
90: * Return a ModelAndView object with the specified view name.
91: */
92: protected ModelAndView handleRenderRequestInternal(
93: RenderRequest request, RenderResponse response)
94: throws Exception {
95:
96: return new ModelAndView(getViewName());
97: }
98:
99: }
|