Data binding an embedded attribute using the [ ] notation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Data binding an embedded attribute using the [ ] notation

longwa
We use several embedded types like Period, Money, etc. in our domain
objects. It's common to have a form which submits a list of new
objects using the syntax:

<g:textField name="embedded[0].period.startDate" value="${someValue}" />
<g:textField name="embedded[1].period.startDate" value="${someValue}" />

It seems like, for the embedded types, the data is not being bound so
the values are always null. For the non-embedded types on the same
object, the values are being set correctly.

There was a ticket http://jira.grails.org/browse/GRAILS-6423 while
back dealing with binding on embedded types, but we are using 2.1.0 so
I assume this has been fixed.

Anyone else trying to do this and having issues? From stepping through
the GrailsDataBinder.autoCreateIfPossible() method, I can't see how it
could ever handle this situation correctly, but I could be easily
missing something.

-Aaron

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Data binding an embedded attribute using the [ ] notation

sergiomichels
I have some troubles with this too. If I have a structure like:

class MyDomain {
   String someAtt
}

class MySubDomain {
  String anotherAtt
  belongsTo = [myDomain: MyDomain]
}

class SomeCoolCommand {
  List<MySubDomain> subDomains = ListUtils.lazyList( [], FactoryUtils.instantiateFactory(MySubDomain) )
}

<input type="text" name="subDomains[0].anotherAtt" /> --> works
<input type="text" name="subDomains[0].myDomain.someAtt" /> --> not works

I have to populate the MyDomain in MySubDomain manually




On Fri, Aug 17, 2012 at 10:34 AM, Aaron Long <[hidden email]> wrote:
We use several embedded types like Period, Money, etc. in our domain
objects. It's common to have a form which submits a list of new
objects using the syntax:

<g:textField name="embedded[0].period.startDate" value="${someValue}" />
<g:textField name="embedded[1].period.startDate" value="${someValue}" />

It seems like, for the embedded types, the data is not being bound so
the values are always null. For the non-embedded types on the same
object, the values are being set correctly.

There was a ticket http://jira.grails.org/browse/GRAILS-6423 while
back dealing with binding on embedded types, but we are using 2.1.0 so
I assume this has been fixed.

Anyone else trying to do this and having issues? From stepping through
the GrailsDataBinder.autoCreateIfPossible() method, I can't see how it
could ever handle this situation correctly, but I could be easily
missing something.

-Aaron

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Data binding an embedded attribute using the [ ] notation

longwa
FWIW,
I found and fixed an issue in the GrailsDataBinder which was
preventing any nested properties from working inside of a collection
(using the [ ] syntax).

https://github.com/grails/grails-core/pull/250

I've posted on the dev list and am hoping this get's considered for
inclusion in 2.1.x branch. I believe it should fix both embedded types
and nested domain objects (although I have only tested the embedded
types).

On Fri, Aug 17, 2012 at 10:49 AM, Sergio Michels
<[hidden email]> wrote:

> I have some troubles with this too. If I have a structure like:
>
> class MyDomain {
>    String someAtt
> }
>
> class MySubDomain {
>   String anotherAtt
>   belongsTo = [myDomain: MyDomain]
> }
>
> class SomeCoolCommand {
>   List<MySubDomain> subDomains = ListUtils.lazyList( [],
> FactoryUtils.instantiateFactory(MySubDomain) )
> }
>
> <input type="text" name="subDomains[0].anotherAtt" /> --> works
> <input type="text" name="subDomains[0].myDomain.someAtt" /> --> not works
>
> I have to populate the MyDomain in MySubDomain manually
>
>
>
>
> On Fri, Aug 17, 2012 at 10:34 AM, Aaron Long <[hidden email]> wrote:
>>
>> We use several embedded types like Period, Money, etc. in our domain
>> objects. It's common to have a form which submits a list of new
>> objects using the syntax:
>>
>> <g:textField name="embedded[0].period.startDate" value="${someValue}" />
>> <g:textField name="embedded[1].period.startDate" value="${someValue}" />
>>
>> It seems like, for the embedded types, the data is not being bound so
>> the values are always null. For the non-embedded types on the same
>> object, the values are being set correctly.
>>
>> There was a ticket http://jira.grails.org/browse/GRAILS-6423 while
>> back dealing with binding on embedded types, but we are using 2.1.0 so
>> I assume this has been fixed.
>>
>> Anyone else trying to do this and having issues? From stepping through
>> the GrailsDataBinder.autoCreateIfPossible() method, I can't see how it
>> could ever handle this situation correctly, but I could be easily
>> missing something.
>>
>> -Aaron
>>
>> ---------------------------------------------------------------------
>> 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