-
Notifications
You must be signed in to change notification settings - Fork 42
Chapter 5 errata
Page 139: Missing params test around register() action
The register actual should check for parameters before performing any updates (to cater for the first hit on the register action). In the updated sample below, a test for if(params) is added...
def register = {
if (params) {
def user = new User(params)
if (user.validate()) {
user.save()
flash.message = "Successfully Create User"
redirect(uri: '/')
} else {
flash.message = "Error Registering User"
return [ user: user ]
}
}
}
Page 146: Uploading to the filesystem (MultipartHttpServletRequest)
The example shows the incoming file upload saved to disk as a gif even though the input format is never determined. Some users have though that transferTo() did some magic transformation in the process, but this is not the case. A production implementation of this example would need to do some work on the byte[] and save in an appropriate format.
The text also mentions that MultipartHttpServletRequest is a class, whilst technically it's an interface. It's the incoming request object that implements this interface in some concrete type. Calling getFile() on an implementation of MultipartHttpServletRequest hands you back an implementation of MultipartFile which you can then call transferTo() method on. For this reason, the variable would be better named mpf rather than mhsr (which is inaccurate).