I'm using Grails 1.1 and the navigation plugin 1.0.4 and just bumped into a problem. I want to have actions from 3 different controllers contribute as subitems to a menu from a different controller.
All examples I saw use the basic case of main menu and subitems directing to actions inside same controller.
I have tried to use a totally separated controller just for the sake of decalring the navigation there, using redirects for the subitems (see below). But in that case, the subitems just don't render.
class ResourceNavController {
// Navigation
static navigation = [ group:'modules', order:100, title:'Test', action:'listResources',
subitems: [
[group:'modules', order:10, title:'Resources', action:'listResources'],
[group:'modules', order:20, title:'Environments', action:'listEnvironments'],
[group:'modules', order:30, title:'Settings', action:'listSettings']
]
]
def listResources = {
redirect(controller:"resource",action:"list")
}
def listEnvironments = {
redirect(controller:"environment",action:"list")
}
def listSettings = {
redirect(controller:"setting",action:"list")
}
}
Any clue?
Thanks, Rollo
Have you tried registering the nav info with explicit controller attributes inside Config.groovy as explained in the docs? (see section "Alternatively, adding items in Config.groovy" 1
It may work, but I don't think it will highlight "active" items correctly. Really this is not ever going to work nicely, what you're doing is not compatible with "convention" based setup.
Navigation plugin 2.0 (no ETA yet) will have a different non-controller based mechanism to detect the currently active menu items, which may work better in this scenario.
You can always email me (the author of the plugin) directly about this.
ok, got another workaround...
change from
def eachSubItem = { attrs, body ->
...
searchKey = GrailsClassUtils.getLogicalName(controllerName, 'Controller')
...
}
to
def eachSubItem = { attrs, body ->
...
searchKey = flash.prevcon ?: GrailsClassUtils.getLogicalName(controllerName, 'Controller')
...
}
and add to all redirect/forward calls "flash.prevcon = controllerName"
class ResourceNavController {
// Navigation
static navigation = [ group:'modules', order:100, title:'Test', action:'listResources',
subitems: [
[group:'modules', order:10, title:'Resources', action:'listResources'],
[group:'modules', order:20, title:'Environments', action:'listEnvironments'],
[group:'modules', order:30, title:'Settings', action:'listSettings']
]
]
def listResources = {
flash.prevcon = controllerName
redirect(controller:"resource",action:"list")
}
def listEnvironments = {
flash.prevcon = controllerName
redirect(controller:"environment",action:"list")
}
def listSettings = {
flash.prevcon = controllerName
redirect(controller:"setting",action:"list")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With