|
I am looking for a grails-y simple solution for this. We have a
domain class called "Company" which contains a SortedSet of "Address" objects. I would like to designate one address as the default address to use. Is there an easy way to do this in grails? TIA. -Z --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
If u want default values in Domain classes, u can just do it that way:
List words = ['hello','goodbye'] And in your case i guess u could do the following: SortedSet addresses = [Address.findByName('default_address')] i dont know exactly whether this works... never used it that way is this what u are looking for?
|
|
Hmm... maybe I am being thick. I am sorry.
A Company has a sortedset of Addresses. We need to be able to choose which one is the default which could change. For example: * Address[0] could be the US headquarters -- DEFAULT * Address[1] could be the EU headquarters The company was originally based in the US but moves to EU. We would want to note that the default is now the EU one. Sorry, but does that help? -Z On 10/8/07, rainer <[hidden email]> wrote: > > If u want default values in Domain classes, u can just do it that way: > > List words = ['hello','goodbye'] > > And in your case i guess u could do the following: > > SortedSet addresses = [Address.findByName('default_address')] > > i dont know exactly whether this works... never used it that way > is this what u are looking for? > > > > > Sean Muse wrote: > > > > I am looking for a grails-y simple solution for this. We have a > > domain class called "Company" which contains a SortedSet of "Address" > > objects. I would like to designate one address as the default address > > to use. > > > > Is there an easy way to do this in grails? > > > > TIA. > > > > -Z > > > > --------------------------------------------------------------------- > > To unsubscribe from this list please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > > > > -- > View this message in context: http://www.nabble.com/GORM---How-To-Model-Default-Entry-of-a-List-Set-tf4590043.html#a13105432 > Sent from the grails - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
I want to have my controller action work with or without an id.
One place I do this is a default UrlMapping for the webapp like: "/"{ controller = "mycontroller" action = "myaction" } In 0.5.6, I could do this in my controller: def myaction = { def x = MyDomain.get( params.id ) if (!x) { // get id from session or somewhere else or even return a nice error msg } ... In 1.0rc1 (and maybe also 0.6 - I don't remember), the above sends an ugly exception out to the web-browser when there is no id in params, i.e. params.id is null. (java.lang.NullPointerException: Cannot get property: class on null object) I have to do something like: def myaction = { def x = params.id ? MyDomain.get( params.id ) : null if (!x) { // get id from session or somewhere else or even return a nice error msg } ... I liked the cleaner 0.5.6 code - it looks nicer, is simpler, and it's just a simple addition to the generated controller code, rather than changing the generated code. Any suggestions for something nicer in 1.0? Thanks, John Allison [hidden email] --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
You need to change your mapping to
"/$id?"{ controller = "mycontroller" action = "myaction" } So that the id is an optional parameter at the end Cheers On 10/8/07, [hidden email] <[hidden email]> wrote: > I want to have my controller action work with or without an id. > > One place I do this is a default UrlMapping for the webapp like: > "/"{ > controller = "mycontroller" > action = "myaction" > } > > > In 0.5.6, I could do this in my controller: > > def myaction = { > def x = MyDomain.get( params.id ) > if (!x) { > // get id from session or somewhere else or even return a nice error msg > } > ... > > > In 1.0rc1 (and maybe also 0.6 - I don't remember), the above sends an > ugly exception out to the web-browser when there is no id in params, > i.e. params.id is null. > (java.lang.NullPointerException: Cannot get property: class on null object) > > I have to do something like: > > def myaction = { > def x = params.id ? MyDomain.get( params.id ) : null > if (!x) { > // get id from session or somewhere else or even return a nice error msg > } > ... > > > I liked the cleaner 0.5.6 code - it looks nicer, is simpler, and it's > just a simple addition to the generated controller code, rather > than changing the generated code. > > Any suggestions for something nicer in 1.0? > > Thanks, > > John Allison > [hidden email] > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > -- Graeme Rocher Grails Project Lead http://grails.org --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by Sean Muse
if u are able to change the value - it is not a default value, then it is an initialization with different values.
Will the US Address ever be default again? Are there e.g. 20 Addresses and [0] and [1] should both be able to be defaults? So, what condition decides, which one is the current default value? :)
|
|
I see what you are saying. The word "default" was probably a poor choice.
Let me try to explain it another way. If I had a Person object with a SortedSet of EmailAddress objects, one of those email addresses would need to be the primary one. That address would be the one the system used as the primary address for emailing that specific person. Thanks for your help. -Z On 10/9/07, rainer <[hidden email]> wrote: > > if u are able to change the value - it is not a default value, then it is an > initialization with different values. > > Will the US Address ever be default again? > > Are there e.g. 20 Addresses and [0] and [1] should both be able to be > defaults? > > So, what condition decides, which one is the current default value? :) > > > > Sean Muse wrote: > > > > Hmm... maybe I am being thick. I am sorry. > > > > A Company has a sortedset of Addresses. We need to be able to choose > > which one is the default which could change. > > > > For example: > > * Address[0] could be the US headquarters -- DEFAULT > > * Address[1] could be the EU headquarters > > > > The company was originally based in the US but moves to EU. We would > > want to note that the default is now the EU one. > > > > Sorry, but does that help? > > > > > > -Z > > > > On 10/8/07, rainer <[hidden email]> wrote: > >> > >> If u want default values in Domain classes, u can just do it that way: > >> > >> List words = ['hello','goodbye'] > >> > >> And in your case i guess u could do the following: > >> > >> SortedSet addresses = [Address.findByName('default_address')] > >> > >> i dont know exactly whether this works... never used it that way > >> is this what u are looking for? > >> > >> > >> > >> > >> Sean Muse wrote: > >> > > >> > I am looking for a grails-y simple solution for this. We have a > >> > domain class called "Company" which contains a SortedSet of "Address" > >> > objects. I would like to designate one address as the default address > >> > to use. > >> > > >> > Is there an easy way to do this in grails? > >> > > >> > TIA. > >> > > >> > -Z > >> > > >> > --------------------------------------------------------------------- > >> > To unsubscribe from this list please visit: > >> > > >> > http://xircles.codehaus.org/manage_email > >> > > >> > > >> > > >> > >> -- > >> View this message in context: > >> http://www.nabble.com/GORM---How-To-Model-Default-Entry-of-a-List-Set-tf4590043.html#a13105432 > >> Sent from the grails - user mailing list archive at Nabble.com. > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe from this list please visit: > >> > >> http://xircles.codehaus.org/manage_email > >> > >> > > > > --------------------------------------------------------------------- > > To unsubscribe from this list please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > > > > -- > View this message in context: http://www.nabble.com/GORM---How-To-Model-Default-Entry-of-a-List-Set-tf4590043.html#a13111274 > Sent from the grails - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by Sean Muse
Why not simply add another field to your Person (or Company) class called 'defaultAddress'. When you're iterating the SortedSet, you can compare to the default to determine which one matches the default. In a view, when rendering a <g:select.../> you can then specify the 'value' attribute as the value of the default and it will automatically set that entry as the selected entry in your select list. As an example.
*shrug* (Everything should be simple, if not simpler) ----- Original Message ---- From: Sean Muse <[hidden email]> To: [hidden email] Sent: Tuesday, October 9, 2007 11:38:14 AM Subject: Re: [grails-user] GORM - How To Model Default Entry of a List/Set I see what you are saying. The word "default" was probably a poor choice. Let me try to explain it another way. If I had a Person object with a SortedSet of EmailAddress objects, one of those email addresses would need to be the primary one. That address would be the one the system used as the primary address for emailing that specific person. Thanks for your help. -Z On 10/9/07, rainer <[hidden email]> wrote: > > if u are able to change the value - it is not a default value, then it is an > initialization with different values. > > Will the US Address ever be default again? > > Are there e.g. 20 Addresses and [0] and [1] should both be able to be > defaults? > > So, what condition decides, which one is the current default value? :) > > > > Sean Muse wrote: > > > > Hmm... maybe I am being thick. I am sorry. > > > > A Company has a sortedset of Addresses. We need to be able to choose > > which one is the default which could change. > > > > For example: > > * Address[0] could be the US headquarters -- DEFAULT > > * Address[1] could be the EU headquarters > > > > The company was originally based in the US but moves to EU. We would > > want to note that the default is now the EU one. > > > > Sorry, but does that help? > > > > > > -Z > > > > On 10/8/07, rainer <[hidden email]> wrote: > >> > >> If u want default values in Domain classes, u can just do it that way: > >> > >> List words = ['hello','goodbye'] > >> > >> And in your case i guess u could do the following: > >> > >> SortedSet addresses = [Address.findByName('default_address')] > >> > >> i dont know exactly whether this works... never used it that way > >> is this what u are looking for? > >> > >> > >> > >> > >> Sean Muse wrote: > >> > > >> > I am looking for a grails-y simple solution for this. We have a > >> > domain class called "Company" which contains a SortedSet of "Address" > >> > objects. I would like to designate one address as the default address > >> > to use. > >> > > >> > Is there an easy way to do this in grails? > >> > > >> > TIA. > >> > > >> > -Z > >> > > >> > --------------------------------------------------------------------- > >> > To unsubscribe from this list please visit: > >> > > >> > http://xircles.codehaus.org/manage_email > >> > > >> > > >> > > >> > >> -- > >> View this message in context: > >> http://www.nabble.com/GORM---How-To-Model-Default-Entry-of-a-List-Set-tf4590043.html#a13105432 > >> Sent from the grails - user mailing list archive at Nabble.com. > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe from this list please visit: > >> > >> http://xircles.codehaus.org/manage_email > >> > >> > > > > --------------------------------------------------------------------- > > To unsubscribe from this list please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > > > > -- > View this message in context: http://www.nabble.com/GORM---How-To-Model-Default-Entry-of-a-List-Set-tf4590043.html#a13111274 > Sent from the grails - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email ____________________________________________________________________________________ Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545433 --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by Sean Muse
my answer is Darryls answer... lol
just flag it by another Address attribute - and do like Darryl wrote Groovy is magic but cant read ya mind ;)
|
|
In reply to this post by graemer
> You need to change your mapping to
> > "/$id?"{ > controller = "mycontroller" > action = "myaction" > } > > So that the id is an optional parameter at the end Getting back to this after my question last week. Thanks for the response. The above suggestion did not change anything, however. params is still an empty hash so params.id evaluates to null and the get method still throws an exception. I can certainly code around it, but it's not as nice as the old way. Also, with the default generated code, if the user edits the id out of the URL, the same thing happens - an ugly exception trace that I'd like to hide from the user. The default if (!object) idiom will do that if the get would just once again return null when it's id argument is null. Thanks, John Allison [hidden email] > Cheers > > On 10/8/07, [hidden email] <[hidden email]> wrote: > > I want to have my controller action work with or without an id. > > > > One place I do this is a default UrlMapping for the webapp like: > > "/"{ > > controller = "mycontroller" > > action = "myaction" > > } > > > > > > In 0.5.6, I could do this in my controller: > > > > def myaction = { > > def x = MyDomain.get( params.id ) > > if (!x) { > > // get id from session or somewhere else or even return a nice error msg > > } > > ... > > > > > > In 1.0rc1 (and maybe also 0.6 - I don't remember), the above sends an > > ugly exception out to the web-browser when there is no id in params, > > i.e. params.id is null. > > (java.lang.NullPointerException: Cannot get property: class on null object) > > > > I have to do something like: > > > > def myaction = { > > def x = params.id ? MyDomain.get( params.id ) : null > > if (!x) { > > // get id from session or somewhere else or even return a nice error msg > > } > > ... > > > > > > I liked the cleaner 0.5.6 code - it looks nicer, is simpler, and it's > > just a simple addition to the generated controller code, rather > > than changing the generated code. > > > > Any suggestions for something nicer in 1.0? > > > > Thanks, > > > > John Allison > > [hidden email] > > > > --------------------------------------------------------------------- > > To unsubscribe from this list please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > > > -- > Graeme Rocher > Grails Project Lead > http://grails.org > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
