-
-
Notifications
You must be signed in to change notification settings - Fork 952
Namespace For Controllers, Domains, Plugins and URL Mappings
jeffbrown edited this page May 8, 2012
·
6 revisions
A limitation in Grails is the fact that certain artifacts must have unique names, even if they are in separate packages. For example an application may not contain both com.demo.UserController and com.demo.admin.UserController. One of the benefits of the new namespace support will be the ability to allow for multiple artifacts, like controllers, to have the same name as they will be associated with different namespaces.
// grails-app/controllers/com/demo/admin/UserController.groovy
package com.demo.admin
class UserController {
static namespace = 'admin'
// ...
}
// grails-app/controllers/com/demo/config/UserController.groovy
package com.demo.config
class UserController {
static namespace = 'config'
// ...
}
// grails-app/controllers/com/demo/UserController.groovy
package com.demo
class UserController {
// ...
}
Special support will be added to URL Mappings for simple handling of mapping namespaces to URLs.
// grails-app/conf/UrlMappings.groovy
class UrlMappings {
static mappings = {
"/$namespace/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
}
}
URL | Controller |
---|---|
/admin/user | com.demo.admin.UserController |
/admin/user/delete/4/ | com.demo.admin.UserController |
/user | com.demo.UserController |
/user/delete/4 | com.demo.UserController |
/config/user | com.demo.config.UserController |
/config/user/delete/4 | com.demo.config.UserController |