Strange case of the disappearing base class

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange case of the disappearing base class

Chris Malan
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?

 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/4524de68-e0b5-48b0-805f-b48837424e94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Strange case of the disappearing base class

Tom Crossland
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:

https://jira.grails.org/browse/GRAILS-11922

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,

On Sunday, March 6, 2016 at 8:47:09 AM UTC+1, Chris Malan wrote:
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?

 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/581c2617-69fa-4f16-94da-16da48505161%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.