Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3398666
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:40:38+00:00 2026-05-18T04:40:38+00:00

How can I dynamically build a list of mappings – instead of: class UrlMappings

  • 0

How can I dynamically build a list of mappings – instead of:

class UrlMappings {
static mappings = {
   "/helpdesk/user/$action?/$id?" (controller="helpdeskuser")
   "/helpdesk/group/$action?/$id?" (controller="helpdeskgroup")
   "/helpdesk/company/$action?/$id?" (controller="helpdeskcompany")
   "/helpdesk/account/$action?/$id?" (controller="helpdeskaccount")
   "/admin/company/$action?/$id?" (controller="admincompany")
   "/admin/account/$action?/$id?" (controller="adminaccount")
 }
}

something like this pseudo code:

class UrlMappings {
static mappings = {
   application.controllerClasses.each {
     if(it.name.startsWith('helpdesk'))
        "/helpdesk/${it.name}/$action?/$id?" (controller="${it.name}")
     if(it.name.startsWith('admin'))
        "/admin/${it.name}/$action?/$id?" (controller="${it.name}")
   }
 }
}

(I don’t understand what the static mappings are – a hash map? free variables?)

What I am trying to achieve are mappings based on the controller type – e.g. helpdesk, admin or user controllers. Once I have set up the mappings I want to add security based on URLs but I don’t want to map each controller individually:

grails.plugins.springsecurity.interceptUrlMap = [
   '/helpdesk/**':   ['ROLE_HELPDESK','ROLE_ADMIN'],
]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:40:38+00:00Added an answer on May 18, 2026 at 4:40 am

    I’ve just done the following in my application:

    import org.codehaus.groovy.grails.commons.ApplicationHolder
    
    class UrlMappings {
      static mappings = {        
        for( controllerClass in ApplicationHolder.application.controllerClasses) {
          // Admin Controllers first
          if( controllerClass.name.startsWith("Admin")){
            // note... fixes the case so that AdminUserController maps to /admin/user
            "/admin/${controllerClass.name[5].toLowerCase() + controllerClass.name[6..-1]}/$action?/$id?" {
              controller = "admin${controllerClass.name[5..-1]}".toString()
            }
          }
        }
      }
    }
    

    I’d not actually done this before, your question prompted me to fix this is my app. It’s been one of those things I’ve been trying to do for a while.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I build a class as shown below dynamically using reflection? There are no
I have a page where the user can dynamically add file upload boxes. Adding
can we dynamically appened where condition on a linq query? for example: class Result
I am trying to build a dynamically generated unordered list in the following format
I am trying to dynamically build a list of admin actions using the get_actions()
I want to dynamically build my list of where conditions. Here's a snippet of
I am writing a container framework that can dynamically deploy a Jar file containing
Does anyone know how I can Dynamically create an installation package that installs files
The problem in my case is I can dynamically add / remove input boxes,
Has anyone come across a software that can dynamically stream an arbitrary source identified

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.