wood burning stoves*
The moose likes Groovy and the fly likes Cascading problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Cascading problem" Watch "Cascading problem" New topic
Author

Cascading problem

Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

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.


My Blog SCJP 5 SCWCD 5
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Aug 18, 2008
Posts: 598

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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Aug 18, 2008
Posts: 598

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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Aug 18, 2008
Posts: 598

Thanks. It worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cascading problem