|
Hi there,
I am trying to bind some data to an object that is part of a command object. The object stays null when trying to use it. Probably i am not giving the correct data in the gsp but i have no clue what am i doing wrong! // the form that submits the data <g:form> <g:textField name="book.title" value="Lord Of the Rings"/><br> <br><br> <g:actionSubmit action="create" value="Create!"/> </g:form> // controller code def create = { BooksBindingCommand cmd -> println cmd?.book?.title // the book property always stays null redirect(action: "index") } // command object class BooksBindingCommand { Book book } // the book class !!! Is no domain class !!! class Book { String title } Any suggestion on why the binding of 'book.title' fails? --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
How about doing a dump() on cmd after the binding to see what's there. On Nov 9, 2011 5:01 PM, "Marco Pas" <[hidden email]> wrote:
Hi there, |
|
The command object is not bound at all, when i use normal properties
all seems ok, so binding works but when i try to bind a nested object instead of property it fails.. and the cmd is null i am trying to bind book.title to a object Book in the Command Object which has a property title. 2011/11/10 Jonathan Rosenberg <[hidden email]>: > How about doing a dump() on cmd after the binding to see what's there. > > On Nov 9, 2011 5:01 PM, "Marco Pas" <[hidden email]> wrote: >> >> Hi there, >> >> I am trying to bind some data to an object that is part of a command >> object. The object stays null when trying to use it. >> Probably i am not giving the correct data in the gsp but i have no >> clue what am i doing wrong! >> >> // the form that submits the data >> <g:form> >> <g:textField name="book.title" value="Lord Of the Rings"/><br> >> <br><br> >> <g:actionSubmit action="create" value="Create!"/> >> </g:form> >> >> // controller code >> def create = { BooksBindingCommand cmd -> >> println cmd?.book?.title // the book property always stays null >> redirect(action: "index") >> } >> >> // command object >> class BooksBindingCommand { >> Book book >> } >> >> // the book class !!! Is no domain class !!! >> class Book { >> String title >> } >> >> Any suggestion on why the binding of 'book.title' fails? >> >> --------------------------------------------------------------------- >> 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 |
|
How are you checking the value of the command object? Logging?
-- Jonathan Rosenberg Founder & Executive Director Tabby's Place, a Cat Sanctuary http://www.tabbysplace.org/ On Thu, Nov 10, 2011 at 11:54 AM, Marco Pas <[hidden email]> wrote: > The command object is not bound at all, when i use normal properties > all seems ok, so binding works > but when i try to bind a nested object instead of property it fails.. > and the cmd is null > > i am trying to bind book.title to a object Book in the Command Object > which has a property title. > > 2011/11/10 Jonathan Rosenberg <[hidden email]>: >> How about doing a dump() on cmd after the binding to see what's there. >> >> On Nov 9, 2011 5:01 PM, "Marco Pas" <[hidden email]> wrote: >>> >>> Hi there, >>> >>> I am trying to bind some data to an object that is part of a command >>> object. The object stays null when trying to use it. >>> Probably i am not giving the correct data in the gsp but i have no >>> clue what am i doing wrong! >>> >>> // the form that submits the data >>> <g:form> >>> <g:textField name="book.title" value="Lord Of the Rings"/><br> >>> <br><br> >>> <g:actionSubmit action="create" value="Create!"/> >>> </g:form> >>> >>> // controller code >>> def create = { BooksBindingCommand cmd -> >>> println cmd?.book?.title // the book property always stays null >>> redirect(action: "index") >>> } >>> >>> // command object >>> class BooksBindingCommand { >>> Book book >>> } >>> >>> // the book class !!! Is no domain class !!! >>> class Book { >>> String title >>> } >>> >>> Any suggestion on why the binding of 'book.title' fails? >>> >>> --------------------------------------------------------------------- >>> 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 > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by marcopas
did you get this working?
I'm facing the same issue |
|
Sadly not.. i could not get it working. I am still very curious why
this does not work. It seems so simple, but my guess is that because the book object is not a real domain object the Spring databinding does not pick this up somehow.. If someone else has a better explained i would like to learn from it! /Marco 2012/1/25 eduardoarantes <[hidden email]>: > did you get this working? > I'm facing the same issue > > -- > View this message in context: http://grails.1312388.n4.nabble.com/How-to-bind-data-to-a-command-object-that-has-an-non-domain-object-as-property-tp4021559p4328613.html > 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 can't bind date also
|
|
In reply to this post by marcopas
Have you tried initially instantiating the object in the command object, like so:
class BooksBindingCommand { Book book = new Book() } Vithun On 25 Jan 2012, at 21:58, Marco Pas wrote: > Sadly not.. i could not get it working. I am still very curious why > this does not work. > > It seems so simple, but my guess is that because the book object is > not a real domain object the Spring databinding does not pick this up > somehow.. > If someone else has a better explained i would like to learn from it! > > /Marco > > 2012/1/25 eduardoarantes <[hidden email]>: >> did you get this working? >> I'm facing the same issue >> >> -- >> View this message in context: http://grails.1312388.n4.nabble.com/How-to-bind-data-to-a-command-object-that-has-an-non-domain-object-as-property-tp4021559p4328613.html >> 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 > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Yep, I ran into the same problem today. Do we need a custom property
editor for this scenario? http://omaha-seattle.blogspot.com/2010/02/custom-grails-property-editor.html Jay On Wed, Jan 25, 2012 at 5:17 PM, Vithun Kumar <[hidden email]> wrote: > Have you tried initially instantiating the object in the command object, like so: > > class BooksBindingCommand { > Book book = new Book() > } > > Vithun > > On 25 Jan 2012, at 21:58, Marco Pas wrote: > >> Sadly not.. i could not get it working. I am still very curious why >> this does not work. >> >> It seems so simple, but my guess is that because the book object is >> not a real domain object the Spring databinding does not pick this up >> somehow.. >> If someone else has a better explained i would like to learn from it! >> >> /Marco >> >> 2012/1/25 eduardoarantes <[hidden email]>: >>> did you get this working? >>> I'm facing the same issue >>> >>> -- >>> View this message in context: http://grails.1312388.n4.nabble.com/How-to-bind-data-to-a-command-object-that-has-an-non-domain-object-as-property-tp4021559p4328613.html >>> 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 >> >> > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > -- ============================== Converting caffeine into code since 1998. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
I checked the tip from Vithun Kumar and it did the trick.. now when i
initialize the object in the Command Object it works as i would expect! So when using: // command object class BooksBindingCommand { Book book = new Book() } It works as expected! I am still wondering why i need to initialize the object? /Marco 2012/1/26 Jay Hogan <[hidden email]>: > Yep, I ran into the same problem today. Do we need a custom property > editor for this scenario? > > http://omaha-seattle.blogspot.com/2010/02/custom-grails-property-editor.html > > Jay > > On Wed, Jan 25, 2012 at 5:17 PM, Vithun Kumar <[hidden email]> wrote: >> Have you tried initially instantiating the object in the command object, like so: >> >> class BooksBindingCommand { >> Book book = new Book() >> } >> >> Vithun >> >> On 25 Jan 2012, at 21:58, Marco Pas wrote: >> >>> Sadly not.. i could not get it working. I am still very curious why >>> this does not work. >>> >>> It seems so simple, but my guess is that because the book object is >>> not a real domain object the Spring databinding does not pick this up >>> somehow.. >>> If someone else has a better explained i would like to learn from it! >>> >>> /Marco >>> >>> 2012/1/25 eduardoarantes <[hidden email]>: >>>> did you get this working? >>>> I'm facing the same issue >>>> >>>> -- >>>> View this message in context: http://grails.1312388.n4.nabble.com/How-to-bind-data-to-a-command-object-that-has-an-non-domain-object-as-property-tp4021559p4328613.html >>>> 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 >>> >>> >> >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > > > -- > ============================== > Converting caffeine into code since 1998. > > --------------------------------------------------------------------- > 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 |
|
When using a domain / model object as a property for the form, i do
not need to initialize the object myself and the framework does that for me. So when having a domain object as property i can do this: // command object class BooksBindingCommand { Book book // Book is model object } and when using a non domain / model object i need to initialize the object. // command object class BooksBindingCommand { Book book = new Book() // Book is a normal object (src/groovy) } The nested properties now work in both cases. /Marco 2012/1/26 Marco Pas <[hidden email]>: > I checked the tip from Vithun Kumar and it did the trick.. now when i > initialize the object in the Command Object it works as i would > expect! > > So when using: > // command object > class BooksBindingCommand { > Book book = new Book() > } > > It works as expected! I am still wondering why i need to initialize the object? > > /Marco > > 2012/1/26 Jay Hogan <[hidden email]>: >> Yep, I ran into the same problem today. Do we need a custom property >> editor for this scenario? >> >> http://omaha-seattle.blogspot.com/2010/02/custom-grails-property-editor.html >> >> Jay >> >> On Wed, Jan 25, 2012 at 5:17 PM, Vithun Kumar <[hidden email]> wrote: >>> Have you tried initially instantiating the object in the command object, like so: >>> >>> class BooksBindingCommand { >>> Book book = new Book() >>> } >>> >>> Vithun >>> >>> On 25 Jan 2012, at 21:58, Marco Pas wrote: >>> >>>> Sadly not.. i could not get it working. I am still very curious why >>>> this does not work. >>>> >>>> It seems so simple, but my guess is that because the book object is >>>> not a real domain object the Spring databinding does not pick this up >>>> somehow.. >>>> If someone else has a better explained i would like to learn from it! >>>> >>>> /Marco >>>> >>>> 2012/1/25 eduardoarantes <[hidden email]>: >>>>> did you get this working? >>>>> I'm facing the same issue >>>>> >>>>> -- >>>>> View this message in context: http://grails.1312388.n4.nabble.com/How-to-bind-data-to-a-command-object-that-has-an-non-domain-object-as-property-tp4021559p4328613.html >>>>> 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 >>>> >>>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe from this list, please visit: >>> >>> http://xircles.codehaus.org/manage_email >>> >>> >> >> >> >> -- >> ============================== >> Converting caffeine into code since 1998. >> >> --------------------------------------------------------------------- >> 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 |
|
Hi!!
Great! It really works. I haven't found anything on the documentation though. I'd like to read something regarding this in GRails doc if someone knows where it is
|
|
In reply to this post by marcopas
This solution has a drawback.
Simple validation like static constraints = { provider blank: false startDate blank: false endDate blank: false } Doesn't seem to work because the values won't be blank ever. Any thoughs?
|
| Powered by Nabble | Edit this page |
