Skip to content

Commit 1f8bdac

Browse files
committed
Merged fix for GRAILS-5811 "Webflow end states don't support dynamic URLs, redirects fail"
1 parent d0d4856 commit 1f8bdac

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

src/java/org/codehaus/groovy/grails/commons/metaclass/PropertyExpression.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package org.codehaus.groovy.grails.commons.metaclass
2626
*
2727
* Created: Jul 22, 2008
2828
*/
29-
class PropertyExpression {
29+
class PropertyExpression implements Cloneable {
3030

3131
private StringBuffer propertyExpression
3232

@@ -43,4 +43,4 @@ class PropertyExpression {
4343
return this
4444
}
4545

46-
}
46+
}

src/java/org/codehaus/groovy/grails/web/mapping/DefaultUrlCreator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ private String createURLWithWebRequest(Map parameterValues, GrailsWebRequest web
6767
HttpServletRequest request = webRequest.getCurrentRequest();
6868

6969
String id = null;
70-
if(parameterValues.containsKey(ARGUMENT_ID)) {
71-
id = parameterValues.get(ARGUMENT_ID).toString();
70+
if (parameterValues.containsKey(ARGUMENT_ID)) {
71+
Object o = parameterValues.get(ARGUMENT_ID);
72+
if(o != null)
73+
id = o.toString();
7274
}
7375

7476

src/java/org/codehaus/groovy/grails/webflow/engine/builder/RuntimeRedirectAction.groovy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ class RuntimeRedirectAction extends AbstractAction{
4848
if(!urlMapper) throw new IllegalStateException("Cannot redirect without an instance of [org.codehaus.groovy.grails.web.mapping.UrlMappingsHolder] within the ApplicationContext")
4949

5050
def delegate = new ExpressionDelegate(context)
51-
controller = resolveExpression(delegate, controller)
52-
action = resolveExpression(delegate, action)
51+
def controller = resolveExpression(delegate, controller)
52+
def action = resolveExpression(delegate, action)
53+
Map params = this.params.clone()
5354
resolveExpressionsInParams(delegate, params)
5455

5556
UrlCreator creator = urlMapper.getReverseMapping(controller, action, params)
56-
def url = creator.createRelativeURL(controller, action, params, 'utf-8')
57+
def url = creator.createRelativeURL(controller, action, params, 'utf-8')
5758

5859
context.getExternalContext().requestExternalRedirect("contextRelative:$url");
5960
return success();
@@ -68,4 +69,4 @@ class ExpressionDelegate extends AbstractDelegate {
6869
super(context);
6970
}
7071

71-
}
72+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.codehaus.groovy.grails.webflow.engine.builder
2+
3+
import org.codehaus.groovy.grails.commons.metaclass.PropertyExpression
4+
import org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingsHolder
5+
import org.springframework.webflow.test.MockRequestContext
6+
import org.springframework.webflow.test.MockExternalContext
7+
import grails.util.GrailsWebUtil
8+
import org.springframework.web.context.request.RequestContextHolder
9+
10+
/**
11+
*
12+
*/
13+
class RuntimeRedirectActionTests extends GroovyTestCase{
14+
15+
void testRedirectWithPropertyExpression() {
16+
GrailsWebUtil.bindMockWebRequest()
17+
18+
try {
19+
def action = new RuntimeRedirectAction()
20+
action.controller = "book"
21+
action.action = "show"
22+
action.params = [id: new PropertyExpression("flow.id")]
23+
action.urlMapper = new DefaultUrlMappingsHolder([])
24+
def ext = new MockExternalContext()
25+
def context = new MockRequestContext()
26+
context.setExternalContext(ext)
27+
context.getFlowScope().put("id", "1")
28+
action.execute(context)
29+
assert "contextRelative:/book/show/1" == ext.getExternalRedirectUrl()
30+
31+
context.getFlowScope().put("id", "2")
32+
action.execute(context)
33+
assert "contextRelative:/book/show/2" == ext.getExternalRedirectUrl()
34+
35+
36+
}
37+
finally {
38+
RequestContextHolder.setRequestAttributes null
39+
}
40+
41+
42+
43+
44+
}
45+
}

0 commit comments

Comments
 (0)