fields icon indicating copy to clipboard operation
fields copied to clipboard

3.0.0.RC1 - f:table does not respect namespace controllers

Open codeconsole opened this issue 6 years ago • 5 comments
trafficstars

Links generated with f:table do not respect namespaces (All other generated tags work).

Replication Example (Grails 4.0.0.RC1): https://github.com/codeconsole/formbinding

git clone https://github.com/codeconsole/formbinding
cd formbinding
sdk use grails 4.0.0.RC2 
grails run-app

Go here: http://localhost:8080/v3/person/index

Click on Name column in table and notice you will be sent here: http://localhost:8080/person/index?sort=name&max=10&order=asc

Which is not in the v3 namepace and is an invalid url. static namespace = 'v3'

codeconsole avatar Jun 05 '19 18:06 codeconsole

I imagine it is a fairly simple fix as g:link tags support the namespace property and you simply need to change

<g:link controller="${c.logicalPropertyName}">${c.fullName}</g:link>

to

<g:link namespace="${c.namespace}" controller="${c.logicalPropertyName}">${c.fullName}</g:link>

If the controller has no namespace, the link tag will still work as normal.

codeconsole avatar Jun 05 '19 18:06 codeconsole

https://github.com/grails/grails-core/issues/10819

codeconsole avatar Jun 15 '19 00:06 codeconsole

If there is no plan in place to fix g:sortableColumn, this plugin should be updated to not use g:sortableColumn in table generation. I would recommend just not allowing the user to sort the column as the current behavior is completely broken,

codeconsole avatar Jun 15 '19 00:06 codeconsole

https://github.com/grails-fields-plugin/grails-fields/blob/master/grails-app/views/templates/_fields/_table.gsp

if the template passes the namespace to the g:sortableColumn, everything works fine except non namespace resources (which do not work either way). Interestingly enough, adding namespace makes namespaced resources work great.

Here is a fix, but might not be the most efficient way of accomplishing it:

change g:sortableColumn from:

<g:sortableColumn property="${p.property}" title="${p.label}" />

to

<g:sortableColumn namespace="${grailsApplication.controllerClasses.findResult{it.logicalPropertyName == controllerName?it.namespace:null}?:''}" property="${p.property}" title="${p.label}" />

codeconsole avatar Jun 15 '19 02:06 codeconsole

I made a pull request on gsp for 3.3.x which gets hopefully merged so we don't need a workaround. https://github.com/grails/grails-gsp/pull/45

fuxx avatar Jul 17 '19 12:07 fuxx