Skip to content

Commit acca7d8

Browse files
committed
Ensure chainModel is combined with final model. Fixes #9626
1 parent 8706ebf commit acca7d8

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRedirector.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import grails.web.mapping.UrlMappings
2525
import grails.web.mapping.UrlMappingsHolder
2626
import grails.web.mapping.mvc.RedirectEventListener
2727
import grails.web.mapping.mvc.exceptions.CannotRedirectException
28+
import grails.web.mvc.FlashScope
2829
import groovy.transform.CompileStatic
2930
import org.grails.core.artefact.ControllerArtefactHandler
3031
import org.grails.core.artefact.DomainClassArtefactHandler
@@ -124,7 +125,7 @@ trait ResponseRedirector implements WebAttributes {
124125
* @return The chainModel
125126
*/
126127
Map getChainModel() {
127-
(Map)getFlash().get("chainModel")
128+
(Map)getFlash().get(FlashScope.CHAIN_MODEL)
128129
}
129130

130131

grails-web-common/src/main/groovy/grails/web/mvc/FlashScope.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
* @author Graeme Rocher
2929
*/
3030
@SuppressWarnings("rawtypes")
31-
public interface FlashScope extends Map, Serializable {
31+
public interface FlashScope extends Map<String, Object>, Serializable {
32+
33+
/**
34+
* The attribute containing the chain model
35+
*/
36+
String CHAIN_MODEL = "chainModel";
3237

3338
/**
3439
* Sets the flash scope to the next state upon a new request

grails-web-common/src/main/groovy/org/grails/web/servlet/GrailsFlashScope.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,27 @@ public boolean containsValue(Object value) {
108108
return (current.containsValue(value) || next.containsValue(value));
109109
}
110110

111-
public Collection values() {
111+
public Collection<Object> values() {
112112
Collection c = new ArrayList();
113113
c.addAll(current.values());
114114
c.addAll(next.values());
115115
return c;
116116
}
117117

118-
public void putAll(Map t) {
119-
for (Map.Entry<Object, Object> entry : ((Map<Object,Object>)t).entrySet()) {
118+
public void putAll(Map<? extends String, ? extends Object> t) {
119+
for (Entry<? extends String, ? extends Object> entry : t.entrySet()) {
120120
put(entry.getKey(), entry.getValue());
121121
}
122122
}
123123

124-
public Set entrySet() {
124+
public Set<Map.Entry<String, Object>> entrySet() {
125125
Set entrySet = new HashSet();
126126
entrySet.addAll(current.entrySet());
127127
entrySet.addAll(next.entrySet());
128128
return entrySet;
129129
}
130130

131-
public Set keySet() {
131+
public Set<String> keySet() {
132132
Set keySet = new HashSet();
133133
keySet.addAll(current.keySet());
134134
keySet.addAll(next.keySet());
@@ -153,7 +153,7 @@ public Object remove(Object key) {
153153
return next.remove(key);
154154
}
155155

156-
public Object put(Object key, Object value) {
156+
public Object put(String key, Object value) {
157157
// create the session if it doesn't exist
158158
registerWithSessionIfNecessary();
159159
if (current.containsKey(key)) {

grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/mvc/UrlMappingsInfoHandlerAdapter.groovy

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import grails.util.Environment
55
import grails.web.mapping.LinkGenerator
66
import grails.web.mapping.ResponseRedirector
77
import grails.web.mapping.UrlMappingInfo
8+
import grails.web.mvc.FlashScope
89
import groovy.transform.CompileStatic
910
import org.grails.web.servlet.mvc.ActionResultTransformer
1011
import org.grails.web.servlet.mvc.GrailsWebRequest
@@ -98,7 +99,17 @@ class UrlMappingsInfoHandlerAdapter implements HandlerAdapter, ApplicationContex
9899
}
99100
else if(result instanceof Map) {
100101
String viewName = controllerClass.actionUriToViewName(action)
101-
return new ModelAndView(viewName, new HashMap<String, Object>((Map)result))
102+
def finalModel = new HashMap<String, Object>()
103+
def flashScope = webRequest.getFlashScope()
104+
if(!flashScope.isEmpty()) {
105+
def chainModel = flashScope.get(FlashScope.CHAIN_MODEL)
106+
if(chainModel instanceof Map) {
107+
finalModel.putAll((Map)chainModel)
108+
}
109+
}
110+
finalModel.putAll((Map)result)
111+
112+
return new ModelAndView(viewName, finalModel)
102113
}
103114
else if(result instanceof ModelAndView) {
104115
return (ModelAndView) result

0 commit comments

Comments
 (0)