I am writing a web app in Grails with the Acegi/Spring Security plug-in, and am having trouble getting it to see changes I make to User instances. I have only been working with Groovy/Grails for about three weeks, so please forgive me if this problem is trivial, since I have been poring over mailing lists and tutorials trying to find the answer.
I have been adding new attributes to the User domain class whenever I need a User to contain more information such as an email confirmation token or real name, since I couldn't find any recommendations to the contrary. Everything seems to be fine for creating new users, but when I edit the user, the changes show up in the user list, but the Acegi tag libraries and associated functions don't seem to see the changes.
Here is the relevant snippet from UserController.update():
def person = User.get(params.id)
//...snip error checking...
//Update user attributes
person.username = params.email
person.email = params.email
person.userRealName = params.userRealName
//Attempt to save changes
if (person.save()) {
//If successful, redirect back to profile viewing page
redirect action: show, id: person.id
return
}
else {
//Otherwise, show errors and edit again
render view: 'edit', model: buildPersonModel(person)
return
}
After this code runs, I can see the changes if I always get user data by ID, but not if I use the Acegi tags or functions. For example, this does not work:
loggedInUserInfo(field:'realName')
But this does:
User.get(loggedInUserInfo(field:'id').toLong()).realName
The new information sometimes shows up after I log out and in again, but usually it doesn't, often not showing up even after three or more relogs. Also, I tried adding "flush:true" to person.save() with no effect.
(Peripheral question: is it bad for me to be fiddling with the User class like this? If not, what's the best way to add information to it?)
Update after more investigation: It looks like if I use loggedInUserInfo() in a normal page, it works fine, but if I use it inside a layout, it exhibits the behavior I described. Could there be some odd caching thing going on?