BadSkillz
BadSkillz

Reputation: 2003

Use controllers globally in Grails

I'm new to Grails and am trying to build a CMS with it. I want the navigation menu to read from the database so a new page will automatically get a link in the navigation. I've been reading Grails: use controller from index.gsp and related questions, but the answers don't seem to work for me. :(

I've created a domain class named Navigation and a template called _header.

In the "Navigation/list" namespace everything works fine, but outside I can't get to the Navigation data.

I've setup url mapping like so:

class UrlMappings {
    static mappings = {
        "/$controller/$action?/$id?"{
            constraints {
                // apply constraints here
            }
        }
        "/"(controller : "Navigation", action : "list")
        "/"(view:"/index")
        "500"(view:'/error')
    }
}

But that doesn't seem to work. Any clues on what could be the problem?

Upvotes: 0

Views: 308

Answers (3)

BadSkillz
BadSkillz

Reputation: 2003

I was looking at the problem all wrong, urlmapping only made the index.gsp redirect to navigation/list. What I was looking for was the

DomainClass.findAll( String query )

propertie to use in the g:each tag

<g:each in="${Navigation.findAll('from Navigation as n where n.css=?', ['ctBoven'])}" var="oNavigation" status="i">

This allows me to read any database from any page.

Upvotes: 0

Maricel
Maricel

Reputation: 2089

Not sure if you are aware of this, but there is an open source CMS built in Grails called Weceem. If you need to use it as part of another Grails application, there is also a grails plug in for Weceem, so you can use it as part of your app.

It might worth looking into it before building a complete new CMS :-)

Upvotes: 0

Burt Beckwith
Burt Beckwith

Reputation: 75671

You have two mappings for "/", your new one and the original one: "/"(view:"/index") - for starters you'll need to remove the other one.

Upvotes: 1

Related Questions