views:

225

answers:

1

Hi I am developing an application under Groovy using scafoldig. We are using the Acegi plugin for security. We have a class called ChangeManagement defined as follows (simplified version)

class ChangeManagement {
static constraints = {
    company(nullable:false)          
    lastModifiedByUser(nullable:false)     
}

Company company    
static belongsToCompany = [company:Company]

User lastModifiedByUser 
static belongsToUser = [lastModifiedByUser:User]
}

When I address the create method I will get a pull-down menu with the label "Last Modified By" with all the users from the table Users, which is the standard behaviour.

Instead of this I would like to have directly the user who is already logged in and no pull down menu. I've already generate the create template and I can modify it. I am assuming that I have to get the username from the session. If my assumption is true, how to get this username? and if I am wrong then from where can I get the username of the current user?

Thanks in advance.

+1  A: 

See this question for details on how to get the current username.

I'd also suggest looking into Grails Filters for one way to easily stuff the user into the model after all controller calls and make it available in the view. I use this on my app to put the name of the logged in user in the upper right hand corner of the screen.

Ted Naleid