Skip to content

Commit d0365bb

Browse files
committed
Fix for GRAILS-9304 g.paginate assumes action is set in UrlMapping
1 parent 7f0f3af commit d0365bb

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

grails-plugin-gsp/src/main/groovy/org/codehaus/groovy/grails/plugins/web/taglib/RenderTagLib.groovy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ class RenderTagLib implements RequestConstants {
347347
def locale = RCU.getLocale(request)
348348

349349
def total = attrs.int('total') ?: 0
350-
def action = (attrs.action ?: (params.action ?: ""))
351350
def offset = params.int('offset') ?: 0
352351
def max = params.int('max')
353352
def maxsteps = (attrs.int('maxsteps') ?: 10)
@@ -363,13 +362,18 @@ class RenderTagLib implements RequestConstants {
363362
if (params.order) linkParams.order = params.order
364363

365364
def linkTagAttrs = [:]
365+
def action
366366
if(attrs.containsKey('mapping')) {
367367
linkTagAttrs.mapping = attrs.mapping
368+
action = attrs.action
368369
} else {
370+
action = attrs.action ?: params.action
371+
}
372+
if(action) {
369373
linkTagAttrs.action = action
370-
if (attrs.controller) {
371-
linkTagAttrs.controller = attrs.controller
372-
}
374+
}
375+
if (attrs.controller) {
376+
linkTagAttrs.controller = attrs.controller
373377
}
374378
if (attrs.id != null) {
375379
linkTagAttrs.id = attrs.id

grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/taglib/RenderTagLibTests.groovy

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ package org.codehaus.groovy.grails.web.taglib
1717

1818
import grails.util.GrailsUtil
1919

20+
import org.codehaus.groovy.grails.commons.UrlMappingsArtefactHandler
2021
import org.codehaus.groovy.grails.support.MockStringResourceLoader
21-
import org.codehaus.groovy.grails.web.pages.FastStringWriter;
22+
import org.codehaus.groovy.grails.web.pages.FastStringWriter
2223
import org.codehaus.groovy.grails.web.pages.GroovyPageBinding
2324
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
2425
import org.codehaus.groovy.grails.web.sitemesh.FactoryHolder
25-
import org.codehaus.groovy.grails.web.sitemesh.GSPSitemeshPage;
26+
import org.codehaus.groovy.grails.web.sitemesh.GSPSitemeshPage
2627
import org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutDecoratorMapper
2728
import org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
28-
import org.codehaus.groovy.grails.web.util.StreamCharBuffer;
2929
import org.springframework.web.servlet.support.RequestContextUtils as RCU
3030

3131
import com.opensymphony.module.sitemesh.RequestConstants
@@ -39,7 +39,6 @@ import com.opensymphony.module.sitemesh.parser.TokenizedHTMLPage
3939
* @author Marcel Overdijk
4040
*/
4141
class RenderTagLibTests extends AbstractGrailsTagTests {
42-
4342
// test for GRAILS-5376
4443
void testPaginateTag() {
4544
def template = '<g:paginate controller="book" total="" offset="" />'
@@ -98,6 +97,28 @@ class RenderTagLibTests extends AbstractGrailsTagTests {
9897
template = '<g:paginate max="2" total="20" offset="14" maxsteps="3" controller="book" action="list" />'
9998
assertOutputContains '<a href="/book/list?offset=16&amp;max=2" class="step">9</a><a href="/book/list?offset=18&amp;max=2" class="step">10</a>', template
10099
}
100+
101+
protected void onInit() {
102+
if(name == 'testPaginateMappingAndAction') {
103+
def mappingClass = gcl.parseClass('''
104+
class TestUrlMappings {
105+
static mappings = {
106+
name claimTab: "/claim/$id/$action" {
107+
controller = 'Claim'
108+
constraints { id(matches: /\\d+/) }
109+
}
110+
}
111+
}
112+
''')
113+
114+
grailsApplication.addArtefact(UrlMappingsArtefactHandler.TYPE, mappingClass)
115+
}
116+
}
117+
118+
void testPaginateMappingAndAction() {
119+
def template = '<g:paginate next="Forward" prev="Back" maxsteps="8" max="10" id="1" mapping="claimTab" total="12" action="documents"/>'
120+
assertOutputEquals '<span class="currentStep">1</span><a href="/claim/1/documents?offset=10&amp;max=10" class="step">2</a><a href="/claim/1/documents?offset=10&amp;max=10" class="nextLink">Forward</a>', template
121+
}
101122

102123
void testPageProperty() {
103124

0 commit comments

Comments
 (0)