one.iota (4) [Avatar] Offline
#1
I'm using Grails 1.3.9 to follow the Hubbub example in Grails in Action.

I've used the command object in section 5.4 (Listing 5.12 and 5.13) and I notice that the profile fields aren't being validated, nor are they being updated. A profile *is* being created by this code, but all the values are null.

The same is true when I use the code from GitHub, though I have not incorporated elements in that code that aren't used yet in Chapter 5 (such as userRole and sendMail stuff).

I have even tried to explicitly save the profile, both via user.profile.save() and profile.save(). For example,

def register = { UserRegistrationCommand urc ->
if (!params.register) return
if (!urc.hasErrors()) {
def props = urc.properties
def user = new User(props)
def profile = new Profile(props)
user.profile = profile
if (!user.save() && profile.save()) {
urc.password = null
urc.passwordRepeat = null
flash.message = "Error registering user"
} else {
redirect(uri: '/')
return [ userDetails : urc ]
}
} else {
urc.password = null
urc.passwordRepeat = null // perhaps not a unique userId
return [ userDetails : urc ]
}
}

Can anyone help?

P.S. Apologies for the code layout - I cannot work out how to get the editor to retain leading white space!
peter.ledbrook (328) [Avatar] Offline
#2
Re: Grails in Action: Chapter 5, command object not updating profile
Sorry for the much delayed response. I believe the issue here is that the names of the fields in the view:

https://github.com/pledbrook/graina/blob/ch05/hubbub/grails-app/views/user/register.gsp#L30

are prefixed with `profile.`. These don't get bound to the command object properties because those property names don't begin with `profile.`. This prefixing *only* works with domain classes.

The solution is to update the view, removing the `profile.` prefix from the field names.
396429 (1) [Avatar] Offline
#3
Re: Grails in Action: Chapter 5, command object not updating profile
peter.ledbrook wrote:Sorry for the much delayed response. I believe the issue here is that the names of the fields in the view: https://skinnyexpress.com/phen375-review-and-results my Phen375 post.

https://github.com/pledbrook/graina/blob/ch05/hubbub/grails-app/views/user/register.gsp#L30

are prefixed with `profile.`. These don't get bound to the command object properties because those property names don't begin with `profile.`. This prefixing *only* works with domain classes.

The solution is to update the view, removing the `profile.` prefix from the field names.


Awesome Peter, just removing profile works perfectly.
574904 (1) [Avatar] Offline
#4
Re: Grails in Action: Chapter 5, command object not updating profile
peter.ledbrook wrote:Sorry for the much delayed response. I believe the issue here is that the names of the fields in the view:

https://github.com/pledbrook/graina/blob/ch05/hubbub/grails-app/views/user/register.gsp#L30

are prefixed with `profile.` https://arynews.tv/en/category/pakistan-elections-2018/ . These don't get bound to the command object properties because those property names don't begin with `profile.`. This prefixing *only* works with domain classes.

The solution is to update the view, removing the `profile.` prefix from the field names.


Hi Awesome Peter...
just removing profile works perfectly.