UrlMappings: static variables in definitions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

UrlMappings: static variables in definitions

Konstantyn Smirnov
Hi all.

I tried to do the following:

class UrlMappings {

  static ACTIONS = [ GET:'ping', DELETE:'deleteAll', POST:'single', PUT:'fullUpdate' ]

  static mappings = {

    "/api/timeslot"( controller:'timeslot' ){ action = ACTIONS }
   
  }
}

class TimeslotController {

  def beforeInterceptor = {
    log.info "request incoming: $request.JSON"
  }

  def ping(){ render 'AAA' }

}


that didn't work out. When I call the url "my.domain.com/api/timeslot" the beforeInterceptor fires, but the action doesn't get resolved.

If I move the action-map to the closure:

"/api/timeslot"( controller:'timeslot' ){ action = [ GET:'ping', DELETE:'deleteAll', POST:'single', PUT:'fullUpdate' ] }

then it works as expected.

There are a couple of use-cases where the use of constants is required.
Reply | Threaded
Open this post in threaded view
|

Re: UrlMappings: static variables in definitions

Ian Roberts
On 20/02/2013 12:29, Konstantyn Smirnov wrote:
> If I move the action-map to the closure:
>
> "/api/timeslot"( controller:'timeslot' ){ action = [ GET:'ping',
> DELETE:'deleteAll', POST:'single', PUT:'fullUpdate' ] }
>
> then it works as expected.

Does the following work?

class UrlMappings {

  static mappings = {
    def ACTIONS = [ GET:'ping', DELETE:'deleteAll', POST:'single',
PUT:'fullUpdate' ]

    "/api/timeslot"( controller:'timeslot' ){ action = ACTIONS }

  }
}

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: UrlMappings: static variables in definitions

Konstantyn Smirnov
I want to define the method-to-actions mapping as a statical variable, so that I'm able to get a hold on it in a GSP or some service.

If I put the map inside the mappings closure, it wouldn't be visible from the outside and doesn't make sense for me...
Reply | Threaded
Open this post in threaded view
|

Re: UrlMappings: static variables in definitions

Steve Ronderos-2
You could try putting it into Config.groovy and then accessing it in each place

Just an idea...

-Steve

On Wednesday, February 20, 2013, Konstantyn Smirnov wrote:
I want to define the method-to-actions mapping as a statical variable, so
that I'm able to get a hold on it in a GSP or some service.

If I put the map inside the mappings closure, it wouldn't be visible from
the outside and doesn't make sense for me...



--
View this message in context: http://grails.1312388.n4.nabble.com/UrlMappings-static-variables-in-definitions-tp4641585p4641615.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: UrlMappings: static variables in definitions

Ian Roberts
On 21/02/2013 00:12, Steve Ronderos wrote:
> You could try putting it into Config.groovy and then accessing it in
> each place
>
> Just an idea...

Though you would have to use grails.util.Holders to access it within the
(static) URL mappings definition closure.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: UrlMappings: static variables in definitions

Konstantyn Smirnov
Ian Roberts wrote
Though you would have to use grails.util.Holders to access it within the
(static) URL mappings definition closure.
do you mean ConfigurationHolder.config? Isn't it deprecated? ;)

still, it's too complicated...

I want to be able to define a good-ol' static variable and use it in a simple way, w/o involving grails magic
Reply | Threaded
Open this post in threaded view
|

Re: UrlMappings: static variables in definitions

Ian Roberts
On 21/02/2013 20:48, Konstantyn Smirnov wrote:
> Ian Roberts wrote
>> Though you would have to use grails.util.Holders to access it within the
>> (static) URL mappings definition closure.
>
> do you mean ConfigurationHolder.config? Isn't it deprecated? ;)

No, I mean grails.util.Holders, which I believe to be the non-deprecated
replacement for ApplicationHolder, ConfigurationHolder etc.

http://grails.org/doc/latest/api/grails/util/Holders.html

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email