Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
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???
-
Hide
- grails8179.zip
- 19/Oct/11 6:45 AM
- 115 kB
- Jeff Brown
-
- grails8179/.classpath 0.7 kB
- grails8179/.gitignore 0.0 kB
- grails8179/.project 0.5 kB
- grails8179/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- grails8179/application.properties 0.1 kB
- grails8179/grails-app/.../BootStrap.groovy 0.5 kB
- grails8179/grails-app/.../BuildConfig.groovy 2 kB
- grails8179/grails-app/conf/Config.groovy 4 kB
- grails8179/grails-app/.../DataSource.groovy 1 kB
- grails8179/grails-app/.../UrlMappings.groovy 0.2 kB
- grails8179/grails-app/.../resources.groovy 0.0 kB
- grails8179/.../PersonController.groovy 0.7 kB
- grails8179/grails-app/.../demo/Person.groovy 0.2 kB
- grails8179/.../messages.properties 3 kB
- grails8179/.../messages_cs_CZ.properties 3 kB
- grails8179/.../messages_da.properties 3 kB
- grails8179/.../messages_de.properties 4 kB
- grails8179/.../messages_es.properties 3 kB
- grails8179/.../messages_fr.properties 2 kB
- grails8179/.../messages_it.properties 2 kB
- grails8179/.../messages_ja.properties 4 kB
- grails8179/.../messages_nl.properties 3 kB
- grails8179/.../messages_pt_BR.properties 3 kB
- grails8179/.../messages_pt_PT.properties 3 kB
- grails8179/.../messages_ru.properties 4 kB
- grails8179/.../messages_sv.properties 3 kB
- grails8179/.../messages_th.properties 5 kB
- grails8179/.../messages_zh_CN.properties 2 kB
- grails8179/grails-app/views/error.gsp 0.3 kB
- grails8179/grails-app/views/index.gsp 3 kB
-
Hide
- sample8179-bug-report-19102011.zip
- 19/Oct/11 7:24 AM
- 27 kB
- Brian Bonner
-
- grails-app/conf/BootStrap.groovy 0.1 kB
- grails-app/conf/BuildConfig.groovy 2 kB
- grails-app/conf/Config.groovy 4 kB
- grails-app/conf/DataSource.groovy 1 kB
- grails-app/conf/UrlMappings.groovy 0.2 kB
- grails-app/conf/spring/resources.groovy 0.0 kB
- grails-app/.../PersonController.groovy 4 kB
- grails-app/domain/com/demo/Person.groovy 0.2 kB
- grails-app/i18n/messages.properties 3 kB
- grails-app/.../messages_cs_CZ.properties 3 kB
- grails-app/i18n/messages_da.properties 3 kB
- grails-app/i18n/messages_de.properties 4 kB
- grails-app/i18n/messages_es.properties 3 kB
- grails-app/i18n/messages_fr.properties 2 kB
- grails-app/i18n/messages_it.properties 2 kB
- grails-app/i18n/messages_ja.properties 4 kB
- grails-app/i18n/messages_nl.properties 3 kB
- grails-app/.../messages_pt_BR.properties 3 kB
- grails-app/.../messages_pt_PT.properties 3 kB
- grails-app/i18n/messages_ru.properties 4 kB
- grails-app/i18n/messages_sv.properties 3 kB
- grails-app/i18n/messages_th.properties 5 kB
- grails-app/.../messages_zh_CN.properties 2 kB
- grails-app/views/error.gsp 0.3 kB
- grails-app/views/index.gsp 3 kB
- grails-app/views/layouts/main.gsp 2 kB
- grails-app/views/person/_form.gsp 3 kB
- grails-app/views/person/create.gsp 2 kB
- grails-app/views/person/edit.gsp 2 kB
- grails-app/views/person/list.gsp 2 kB
-
- screenshot-1.jpg
- 74 kB
- 19/Oct/11 7:27 AM
-
- screenshot-2.jpg
- 88 kB
- 19/Oct/11 7:29 AM
-
- screenshot-3.jpg
- 121 kB
- 19/Oct/11 7:30 AM
Activity
Yes, I'll pull the app in, try it out and take a look. I'll try to create a small screencast which shows the problem I'm seeing.
Jeff, I looked at the sample and it doesn't look like the views were generated with 2.0.0.M2 (i.e. there's no way to create an entity) in the view. I might have associated this bug with the wrong component.
When I try to use the view (based on the template) created with generate-all, and bind it using Person person = new Person(params), and then try to save it, it doesn't save it properly and throws errors back to the UI. There may be a common work around, or I'm missing something simple, but that's what's happening.
I'll include my sample app generated with 2.0.0.M2.
I've entered in information from all the fields and I'm going to press the 'Create' button.
Hopefully this clarifies the error I'm seeing. Thanks for looking at it.
Support for embedded objects in scaffolding is not completely implemented yet
What would be the best approach for including them in the template and pulling them off the inbound request? I'm happy to try to help.
Point me in the right direction and I'll have a go at it.
It looks like the wrong input field type names are being rendered out to the template so they are properly ingested by the controller.
it was rendering the property names as 'city', 'state', 'zipCode', etc. as if they were on the same level as person...which is obviously not right...
here's a sample of the broken query string:
city=Wyoming&state=OH&street=Mt+Pleasant&zipCode=45215&name=Brian&city=Blue+Ash&state=OH&street=Ashview&zipCode=45242&create=Create
What should the field names format look like?
Should they have a dotted notation? (e.g. person.homeAddress.city) or should they have some other separator?
Let me know if I can help.
The logic that needs changing is in _form.gsp and DefaultGrailsTemplateGenerator
https://github.com/grails/grails-core/blob/master/grails-resources/src/grails/templates/scaffolding/_form.gsp
https://github.com/grails/grails-core/blob/master/grails-crud/src/main/groovy/org/codehaus/groovy/grails/scaffolding/DefaultGrailsTemplateGenerator.groovy#L83
There is some logic in there to deal with embedded but it isn't properly implemented yet
Is there a special MAP syntax within the Parameter Map to support embedded objects?
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.
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 ![]()
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
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...
See the attached app. A new Person is created in BootStrap.groovy and appears to work fine. Can you clarify what it takes to create the problem?
Thanks for the help.