if(Integer.parseInt(params.user.id) != user.id){
...
}
if(params.int('user.id') != user.id){
...
}
There are other methods which the params object has to easily convert HTTP post values to well known data types, such as:
param.short(...)
param.byte(...)
param.long(...)
param.double(...)
param.boolean(...)
Another nice feature is that these methods accept a second optional parameter, which is the default that the value is set to, in the case that there is an error in the conversion:
def price = prams.float("seventy", 0.0)
This behaviour is documented in the Grails documentation here. Although, there doesn't seem to be a comprehensive list of the methods available at the time of writing.
No comments:
Post a Comment