Dónal
Dónal

Reputation: 187499

bind domain class by unique name

My Grails app has the following command object

class MyCommand {

    @BindUsing({
        obj, source ->
            User.findByUsername(source.username)
    })
    User user

    // other stuff not relevant to this question
}

The request parameters includes a username which uniquely identifies the User. I've added the @BindUsing annotation in order to bind the user property of the command object to the corresponding User instance. However, after databinding has completed, the user field is null, even though the username parameter is correct. What am I doing wrong?

Upvotes: 3

Views: 218

Answers (1)

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27200

I don't think this has anything to do with retention policy, dynamic finders, withTransaction or withSession. The issue is that the @BindUsing closure is only triggered for the "user" property if there is a request parameter named "user". The description suggests that there probably isn't one in play in this scenario.

Upvotes: 5

Related Questions