0

I am writing a controller method which needs to pass a string param as the Domain name and int param as the key, then use Domain.get(id) to get the Domain instance.

Could anyone show me how to do it? I've tried

${params.DomainName}.get(params.DomainId as int)

but no luck.

Thanks.

Gregg
  • 34,973
  • 19
  • 109
  • 214

1 Answers1

0

You can use getDomainClass() for this purpose.

def className = params.domainName  //com.somepackage.MyClass
def clazz = grailsApplication.getDomainClass(className).clazz
def entry = clazz.get(params.long('domainId'))
Pavel Savchyk
  • 362
  • 1
  • 16