Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cascading problem

 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an object which contains the reference to other object. Its like Person has a reference of Address Object.

The problem is that the view comes with the drop down instead of the text box. Is there something which I am doing wrong?




Please help.

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you enter an Address into a textbox? Your Address object contains 2 properties that the user would need to populate. Anytime you have an object reference grails is generally going to use a dropdown to choose the object. You can always modify the generated HTML to be more what you want.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was planning that during the registration the user will fillin the information and the address will be saved in the address table with its id in the Person Table.
I thought that there must be some quick may to merge the views and the save method.
Also can you suggest that to do this kind of stuff making a service will be better or I can use the address controller in person controller.

Thanks for the reply.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himanshu Gupta wrote:I was planning that during the registration the user will fillin the information and the address will be saved in the address table with its id in the Person Table.
I thought that there must be some quick may to merge the views and the save method.
Also can you suggest that to do this kind of stuff making a service will be better or I can use the address controller in person controller.

Thanks for the reply.


Grails can't yet read your mind. You'll just need to merge them however you see fit. Scaffolding is great for learning, but you'll soon find out it isn't something you rely on heavily.

As to your service question, again, forget scaffolding. If you didn't have code generated for you, how would you do this? Hint: Using controllers from controllers isn't an option.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read it like making a service and calling it from the controller so that it can save and do the mapping (id) for me.
I think here I have to make use of hql.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himanshu Gupta wrote:I read it like making a service and calling it from the controller so that it can save and do the mapping (id) for me.
I think here I have to make use of hql.


There shouldn't be any hql required for what you're trying to do. A service call, sure. But it should just be standard GORM save() method calls. Why don't you show us the code for your view and then show us what you think the service method should look like? Then we can direct you from there.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Vendor class has the Address reference.
Both Vendor and Address has their own controllers.

This is the code of the gsp.


Please let me know of you need to look at some more code.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So a few things...

1) You don't need an id defined in your Person domain. So remove that.
2) Address will need to be nullable in Person. Then you can do something like this...



Ultimately, you'd probably want both saves in a service so they are transactional. But that is the gist of it.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. It worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic