views:

110

answers:

2

Like here in stackoverflow if i force put bad characters on URL in id place it redirects you to a page error. I would like to know if with Grails it has some kind of plugin for prevent id like: "123$#3" or an easy way because i have a lot of actions and do something like below dont seems to be the best way:


def find = {   

     def val = OwnStringUtilsClass.verify(params.id)
     val ? Book.get(val) : response.sendError(404)
}
A: 

You could try using a controller filter.

Veeti
+1  A: 

You can use the following in grails-app/conf/UrlMappings.groovy:

  "/$controller/$action?/$id?"{
          constraints {
                    id(matches:/\d*/)
              }
      }

This will ensure that the id is numeric.

Robert Munteanu