tags:

views:

907

answers:

6

Hello,

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

A: 

What does your gsp look like? ... i.e:

<nav:render group="modules" /><br />
<nav:renderSubItems group="modules" />
Yes, that's how it is
Rollo Tomazzi
+2  A: 

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.

Marc Palmer
A: 

class ResourceNavController {

// Navigation static navigation = [ group:'modules', order:100, title:'Test', action:'listResources', subitems: ['listResources','listEnvironments','listSettings'] ]

def listResources = { [ redirect(controller:"resource",action:"list")] }

def listEnvironments = { [ redirect(controller:"environment",action:"list")] }

def listSettings = { [redirect(controller:"setting",action:"list")] }

}

mbayloon
A: 

solved it for my problem!!!!

i dont know if this is the best solution, but for me it works like a charm... if i get a better solution i will let u know...

change at NavigationTagLib.groovy from

def eachSubItem = { attrs, body ->
...
   searchKey = GrailsClassUtils.getLogicalName(controllerName, 'Controller')
...
}

to

def eachSubItem = { attrs, body ->
...
   searchKey = GrailsClassUtils.getLogicalName(controllerName, 'Controller').split(/[A-Z]/)[0]
...
}

the convention is (for this change the example to):

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:"resourcenavResource",action:"list")
}

def listEnvironments = {
        redirect(controller:"resourcenavEnvironment",action:"list")
}

def listSettings = {
        redirect(controller:"resourcenavSetting",action:"list")
}

}

grails-version: 1.3.4 navigation-version: 1.1.1


Hi,

at first thanks for your great work so far.

Is there a solution of the problem?

I just upgraded from grails 1.2.1 to 1.3.4 and running into this problem, with 1.2.1 there wasn't that problem (why ever, havn't debugged so far).

THX

jan
A: 

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")
}

}
jan
A: 

The easiest way to solve this problem is to edit NavigationService.groovy and change line 62:

this

result.controller = p.controller

into

result.controller = subitem.controller ? subitem.controller : p.controller

Than u can set the controller param in the Navigation parameters, like this:

static navigation = [
    group: 'tabs',
    order: 1,
    title: 'Title',
    subItems: [
            [action: 'list', title: 'Title 1'],
            [action: 'anotherList', title: 'Another title'],
            [controller: 'someOtherController', action: 'list', title: 'Last title'],
    ],
]
Maciej