views:

167

answers:

1

Hi,

I have a menu that loaded from main layout. in the menu I have to highlight the specific menu if users click on that menu. I detect it based on Controller name.

I have 2 menu that has different names ie Users Edit and Client Edit. Both actually share the same controller (ie: UserController) and same Domain.

I tried to create alias for that in UrlMappings such as : "/client/edit/"(controller:"user",action:"edit")

but on the main layout, it seems didn't recognized as "client" but as "user"

is there any nice way to solve this problem without duplicating controller ? can i inherit controller ? if so how to do that ...

thank you very much.

A: 

use a filter to add to the model the controller name and modify it to suit:

e.g. put this in the /grails-app/conf/MenuAddingFilter.groovy

class MenuAddingFilter {
   static filter = {
      all(controller:'*', action:'*') {
         after = { model ->
            model.menuName = controllerName.replace("Controller","")
         }
      }  
   }   
}

then in your .gsp page, you will have the menuName property available for use. see http://www.grails.org/Filters for more info.

Chii