This plugin gives you an Breadcrumb based on a definition of the navigation structure (implementation of a "menuDefinitionService" service). A simple breadcrumb editable and robust. the construction of the breadcrumb is based on the couple action / controller. An annotation allows you to change the breadcrumb. Very flexible and easy to implement.
compile ":groovy-breadcrumbs-plugin:1.0.2"
The breadcrumbs plugin is based on a MenuDefinitionService is provided by the application. So let's go create the service
Run create-service MenuDefinitionService
In MenuDefinitionService create a method called loadMenuDefinition
example
class MenuDefinitionService {
static transactional = false
static scope = "session"
static proxy = true
def loadMenuDefinition() {
def menus = []
menus << new MenuItem(name : "page-one", message:"page.one.demo", controller: "BreadCrumbsDemo", action: "pageOne")
MenuItem menuThreeTwo = new MenuItem(name : "page-two-", message:"page.two.demo", controller: "BreadCrumbsDemo", action:"pageThreeTwo")
menuThreeTwo << new MenuItem(name : "page-two.one", message:"page.two.one.demo", controller: "BreadCrumbsDemo", action:"pageThreeTwoOne")
menuThreeTwo << new MenuItem(name : "page-two.two", message:"pagetwo.two.demo", controller: "BreadCrumbsDemo", action:"pageThreeTwoTwo")
menus << menuThreeTwo
menus
}
}
You can define as many levels that you want !!!
Just define the message in messages.properties
like page.two.demo=pageTwo
Declare Service MenuDefinitionService
as proxy in resources.groovy
beans = {
...
menuDefinitionServiceProxy(org.springframework.aop.scope.ScopedProxyFactoryBean) {
targetBeanName = 'menuDefinitionService'
proxyTargetClass = true
}
...
}
Now the end, for define the divider of breadcrumbs
add grails configuration in config.groovy
breadcrumbs.divider = ">"
You can define all > < / - ...
divider that you want
You can also define html character like > or <
or ¥
if you want :)
Adding the taglib in your layout
<crumbs:breadcrumbs />
To redefine breadcrumb use @BreadCrumbs
The breadcrumb can be reset by three ways
Example with static scope
@BreadCrumbs (scope = BreadCrumbsScopeEnum.STATIC, actionName = "actionName", ControllerName = "ControllerName")
def controllerMethod() {
....
}
Example with request scope
@BreadCrumbs (scope = BreadCrumbsScopeEnum.REQUEST, actionName = "actionName", ControllerName = "ControllerName")
def controllerMethod() {
....
}
Example with session scope
@BreadCrumbs (scope = BreadCrumbsScopeEnum.SESSION)
def controllerMethod() {
breadCrumbsService.pushActionInSession ("actionName")
and / or
breadCrumbsService.pushControllerInSession ("controllerName")
....
}
breadcrumbs.enable.clickable=true
breadcrumbs.enable.home=true
Two mode are possible
breadcrumbs.home.type="image"
breadcrumbs.home.type="message"
Add a getHomeItem()
in MenuDefinitionService
Example for image mode
def getHomeItem(){
def message = "breadcrumbs/menu_home.png"
def home = new MenuItem(name:"page-home", message: message);
home
}
Or for message mode
def getHomeItem(){
def home = new MenuItem(name:"page-home", message: "message key");
home
}
define a css for
.breadcrumb
for
.breadcrumb > li
and for active item
.breadcrumb > li > .active