Discussion:
urlmappings - embedded variables interspersed with hard-coded tokens
John Holme
2014-05-16 17:28:14 UTC
Permalink
I've got the following entry in UrlMappings.groovy:

"/sites/$sitecode/bibs/$bibId/holds"(controller:"holds", action:"create",
method:"POST")

The intention is to provide a RESTful API that reveals a resource hierarchy.
Constraints on both the sitecode and bibId fields in HoldsCommand include
nullable:false and blank:false. However, the following URI returns 'blank'
errors for both fields:

localhost:8080/myapp/sites/alb/bibs/abc/holds

What is the correct way to map this url?



--
View this message in context: http://grails.1312388.n4.nabble.com/urlmappings-embedded-variables-interspersed-with-hard-coded-tokens-tp4656912.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
John Holme
2014-05-16 17:45:25 UTC
Permalink
It works fine when I use 'params' instead of the command object....



--
View this message in context: http://grails.1312388.n4.nabble.com/urlmappings-embedded-variables-interspersed-with-hard-coded-tokens-tp4656912p4656914.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
John Holme
2014-05-16 18:29:31 UTC
Permalink
Here's a workaround:

def create(HoldsCommand hc) {
*hc.sitecode = params.sitecode*
*hc.bibId = params.bibId*
println "sitecode: ${hc.sitecode}"
println "bibId: ${hc.bibId}"
if (!hc.validate()) {
renderAsJSON(formatErrors(hc))
return
}
def holdDTO = new HoldDTO(hc)
holdDTO = holdsService.create(holdDTO)
renderAsJSON(holdDTO)
}

Is there a way to make the Command object do this itself without the
explicit assignments from the params object?



--
View this message in context: http://grails.1312388.n4.nabble.com/urlmappings-embedded-variables-interspersed-with-hard-coded-tokens-tp4656912p4656915.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

Loading...