Grails Scaffolding Plugin
  1. Grails Scaffolding Plugin
  2. GPSCAFFOLD-47

Domain Objects with Embedded Grails Classes in src/groovy are not being bound properly

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Ubuntu 10.04 64-bit OpenJDK 6

      Description

      package dummy
      
      class Person {
      
         static embedded = ['homeAddress', 'workAddress']
      
         String name
      
         Address homeAddress = new Address()
         Address workAddress = new Address()
      }
      
      package dummy
      
      class Address {
      
         String street
         String city
         String state
         String zipCode
      }
      
      >> generate-all dummy.Person
      

      When I run the resulting error when trying to create a person w/o all the field filled in is:

      Property [city] of class [class dummy.Address] cannot be null
      Property [state] of class [class dummy.Address] cannot be null
      Property [street] of class [class dummy.Address] cannot be null
      Property [zipCode] of class [class dummy.Address] cannot be null
      Property [city] of class [class dummy.Address] cannot be null
      Property [state] of class [class dummy.Address] cannot be null
      Property [street] of class [class dummy.Address] cannot be null
      Property [zipCode] of class [class dummy.Address] cannot be null
      

      What am I doing wrong???

      1. screenshot-1.jpg
        74 kB
      2. screenshot-2.jpg
        88 kB
      3. screenshot-3.jpg
        121 kB

        Activity

        Hide
        Brian Bonner added a comment -

        Is there a special MAP syntax within the Parameter Map to support embedded objects?

        Show
        Brian Bonner added a comment - Is there a special MAP syntax within the Parameter Map to support embedded objects?
        Hide
        Brian Bonner added a comment -

        OK, it is a dotted notation.

        Something like this 'should' work:

        Map params = ['name':'Brian','homeAddress.state':'OH','homeAddress.city':'Cincinnati']

        def person = new Person(params)

        So just prefixing the input names with the name of the property, should solve the problem. I'll take a look and see if I can help with the TemplateGenerator.

        Show
        Brian Bonner added a comment - OK, it is a dotted notation. Something like this 'should' work: Map params = ['name':'Brian','homeAddress.state':'OH','homeAddress.city':'Cincinnati'] def person = new Person(params) So just prefixing the input names with the name of the property, should solve the problem. I'll take a look and see if I can help with the TemplateGenerator.
        Hide
        Brian Bonner added a comment -

        So it looks like the renderEditor, which is referenced here: https://github.com/grails/grails-core/blob/master/grails-resources/src/grails/templates/scaffolding/_form.gsp#L43 might be part of the issue, I suspect it's what's rendering the input field.

        I see your second link pointed me to the renderEditor closure.

        I have to see these in action

        Show
        Brian Bonner added a comment - So it looks like the renderEditor, which is referenced here: https://github.com/grails/grails-core/blob/master/grails-resources/src/grails/templates/scaffolding/_form.gsp#L43 might be part of the issue, I suspect it's what's rendering the input field. I see your second link pointed me to the renderEditor closure. I have to see these in action
        Hide
        whisky Tuladhar added a comment -

        Has this issue been resolved?
        I am using Spring Tool Suite. When trying to save the homeaddress (embedded class), I am getting message saying "Property [homeAddress] of class [class com.stockgroup.trading.Trader] cannot be null".
        Can you please let us know what is the solution for this?
        Thanks

        Show
        whisky Tuladhar added a comment - Has this issue been resolved? I am using Spring Tool Suite. When trying to save the homeaddress (embedded class), I am getting message saying "Property [homeAddress] of class [class com.stockgroup.trading.Trader] cannot be null". Can you please let us know what is the solution for this? Thanks
        Hide
        Nirav Parmar added a comment -

        Hi..
        In your domain class you have define your variable like
        String RollNo
        String Name

        So your variable name should start with small letter like
        String rollNo
        String name

        Now try it!!

        I have tried and it works for me...

        Show
        Nirav Parmar added a comment - Hi.. In your domain class you have define your variable like String RollNo String Name So your variable name should start with small letter like String rollNo String name Now try it!! I have tried and it works for me...

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Brian Bonner
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: