Strange case of the disappearing base class

20 views
Skip to first unread message

Chris Malan

unread,
Mar 6, 2016, 2:47:09 AM3/6/16
to Grails Dev Discuss
Scenario: extend a Person class from a Spring Security User class.  The first user is created in Bootstrap.groovy so one can have access to the application.  This user does not use the extended Person class.  With the application up and running sign in as this Bootstrap created User and create a Person.  The person will have all the attributes of the Spring Security User as well as the Person.  Now try the show view of the User.  Here's the generated code:
    def show(SecUser secUser) {
        respond secUser
    }

Only the Bootstrap generated User shows.  The other one has no data in it.

Now change the code to this:
    def show(SecUser secUser) {
        [secUser: secUser]
    } 

Both users now show, the Bootstrap generated one as a User and the other one as a Person.

What exactly is the difference between 'respond user' and [user: user]?  I know the second one is an explicit Map and it's clear they behave differently.  Where should one use which one?

 

Tom Crossland

unread,
Mar 7, 2016, 4:36:10 AM3/7/16
to Grails Dev Discuss
I suspect this may be due to the way `DefaultHtmlRenderer` determines variable names for the model. It looks similar to a problem I reported with collection respones:


If I remember correctly, for a single object response, "respond" will use the concrete domain class name (in this case "person" instead of "secUser"). I would suggest always specifying the model variable names explicitly when working with inheritance hierarchies.

Hope that helps,
Reply all
Reply to author
Forward
0 new messages