44
44
*/
45
45
public class ModelAndViewContainer {
46
46
47
- private Object view ;
47
+ private boolean ignoreDefaultModelOnRedirect = false ;
48
48
49
- private boolean requestHandled = false ;
49
+ private Object view ;
50
50
51
51
private final ModelMap defaultModel = new BindingAwareModelMap ();
52
52
53
53
private ModelMap redirectModel ;
54
54
55
55
private boolean redirectModelScenario = false ;
56
56
57
- private boolean ignoreDefaultModelOnRedirect = false ;
58
-
59
57
private final SessionStatus sessionStatus = new SimpleSessionStatus ();
60
58
59
+ private boolean requestHandled = false ;
60
+
61
+
62
+ /**
63
+ * By default the content of the "default" model is used both during
64
+ * rendering and redirect scenarios. Alternatively controller methods
65
+ * can declare an argument of type {@code RedirectAttributes} and use
66
+ * it to provide attributes to prepare the redirect URL.
67
+ * <p>Setting this flag to {@code true} guarantees the "default" model is
68
+ * never used in a redirect scenario even if a RedirectAttributes argument
69
+ * is not declared. Setting it to {@code false} means the "default" model
70
+ * may be used in a redirect if the controller method doesn't declare a
71
+ * RedirectAttributes argument.
72
+ * <p>The default setting is {@code false}.
73
+ */
74
+ public void setIgnoreDefaultModelOnRedirect (boolean ignoreDefaultModelOnRedirect ) {
75
+ this .ignoreDefaultModelOnRedirect = ignoreDefaultModelOnRedirect ;
76
+ }
61
77
62
78
/**
63
79
* Set a view name to be resolved by the DispatcherServlet via a ViewResolver.
@@ -100,32 +116,10 @@ public boolean isViewReference() {
100
116
}
101
117
102
118
/**
103
- * Signal a scenario where the request is handled directly.
104
- * <p>A {@link HandlerMethodReturnValueHandler} may use this flag to
105
- * indicate the response has been fully handled and view resolution
106
- * is not required (e.g. {@code @ResponseBody}).
107
- * <p>A {@link HandlerMethodArgumentResolver} may also use this flag
108
- * to indicate the presence of an argument (e.g.
109
- * {@code ServletResponse} or {@code OutputStream}) that may lead to
110
- * a complete response depending on the method return value.
111
- * <p>The default value is {@code true}.
112
- */
113
- public void setRequestHandled (boolean requestHandled ) {
114
- this .requestHandled = requestHandled ;
115
- }
116
-
117
- /**
118
- * Whether the request is handled directly.
119
- */
120
- public boolean isRequestHandled () {
121
- return this .requestHandled ;
122
- }
123
-
124
- /**
125
- * Return the model to use: the "default" or the "redirect" model.
126
- * <p>The default model is used if {@code "redirectModelScenario=false"} or
127
- * if the redirect model is {@code null} (i.e. it wasn't declared as a
128
- * method argument) and {@code ignoreDefaultModelOnRedirect=false}.
119
+ * Return the model to use -- either the "default" or the "redirect" model.
120
+ * The default model is used if {@code redirectModelScenario=false} or
121
+ * there is no redirect model (i.e. RedirectAttributes was not declared as
122
+ * a method argument) and {@code ignoreDefaultModelOnRedirect=false}.
129
123
*/
130
124
public ModelMap getModel () {
131
125
if (useDefaultModel ()) {
@@ -154,25 +148,13 @@ public void setRedirectModel(ModelMap redirectModel) {
154
148
}
155
149
156
150
/**
157
- * Signal the conditions are in place for using a redirect model.
158
- * Typically that means the controller has returned a redirect instruction .
151
+ * Whether the controller has returned a redirect instruction, e.g. a
152
+ * "redirect:" prefixed view name, a RedirectView instance, etc .
159
153
*/
160
154
public void setRedirectModelScenario (boolean redirectModelScenario ) {
161
155
this .redirectModelScenario = redirectModelScenario ;
162
156
}
163
157
164
- /**
165
- * When set to {@code true} the default model is never used in a redirect
166
- * scenario. So if a redirect model is not available, an empty model is
167
- * used instead.
168
- * <p>When set to {@code false} the default model can be used in a redirect
169
- * scenario if a redirect model is not available.
170
- * <p>The default setting is {@code false}.
171
- */
172
- public void setIgnoreDefaultModelOnRedirect (boolean ignoreDefaultModelOnRedirect ) {
173
- this .ignoreDefaultModelOnRedirect = ignoreDefaultModelOnRedirect ;
174
- }
175
-
176
158
/**
177
159
* Return the {@link SessionStatus} instance to use that can be used to
178
160
* signal that session processing is complete.
@@ -181,6 +163,24 @@ public SessionStatus getSessionStatus() {
181
163
return this .sessionStatus ;
182
164
}
183
165
166
+ /**
167
+ * Whether the request has been handled fully within the handler, e.g.
168
+ * {@code @ResponseBody} method, and therefore view resolution is not
169
+ * necessary. This flag can also be set when controller methods declare an
170
+ * argument of type {@code ServletResponse} or {@code OutputStream}).
171
+ * <p>The default value is {@code false}.
172
+ */
173
+ public void setRequestHandled (boolean requestHandled ) {
174
+ this .requestHandled = requestHandled ;
175
+ }
176
+
177
+ /**
178
+ * Whether the request has been handled fully within the handler.
179
+ */
180
+ public boolean isRequestHandled () {
181
+ return this .requestHandled ;
182
+ }
183
+
184
184
/**
185
185
* Add the supplied attribute to the underlying model.
186
186
* A shortcut for {@code getModel().addAttribute(String, Object)}.
0 commit comments