Quantcast

Binding with Map properties

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Binding with Map properties

bksaville

This is less of a problem and more of a question to see if anyone knows where it comes from.  I’ve been using the binding pattern of the implicit constructor or setting of properties:

 

def obj = new MyClass(params)

or

def obj = new MyClass()

obj.properties = params

 

But I noticed that when I upgraded to grails 2.0.1 (I’m sure this is more internal to groovy itself), my properties that are Maps are no longer binding correctly.  I have not tested whether bindData has this same issue.  So for an example domain class:

 

class MyClass {

                Map myMap

}

 

Then if try to create the object like this:

 

def obj = new MyClass(myMap:[test:true])

assert obj.myMap.test

 

This will fail.  Just curious if anyone knows about this or has any input on something I might be doing wrong.

 

Thanks,

Brian

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Binding with Map properties

Graeme Rocher-2
It is a known issue, but yes, currently we filter out maps to avoid the scenario where a map is bound to an association. However, we should only be doing this is if the target property is a domain class not if it is a map. I believe there is already a JIRA for this.. will try dig it up

Cheers

-- 
Graeme Rocher

On Thursday, February 23, 2012 at 4:07 PM, Brian Saville wrote:

This is less of a problem and more of a question to see if anyone knows where it comes from.  I’ve been using the binding pattern of the implicit constructor or setting of properties:

 

def obj = new MyClass(params)

or

def obj = new MyClass()

obj.properties = params

 

But I noticed that when I upgraded to grails 2.0.1 (I’m sure this is more internal to groovy itself), my properties that are Maps are no longer binding correctly.  I have not tested whether bindData has this same issue.  So for an example domain class:

 

class MyClass {

                Map myMap

}

 

Then if try to create the object like this:

 

def obj = new MyClass(myMap:[test:true])

assert obj.myMap.test

 

This will fail.  Just curious if anyone knows about this or has any input on something I might be doing wrong.

 

Thanks,

Brian


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Binding with Map properties

bksaville
They are simple maps – in fact since we use mongo, we don’t have any
restrictions on the contents of the map (ie string->string).  But they are
definitely not domain classes.  I thought the implicit constructor was a
property of groovy itself and not of grails, or do you modify the default
behavior?

I’d love the ticket if you can find it – I’ve tried searching multiple times
but haven’t come up with anything.

Thanks!
-Brian

From: Graeme Rocher [mailto:[hidden email]]
Sent: Thursday, February 23, 2012 8:21 AM
To: [hidden email]
Subject: Re: [grails-user] Binding with Map properties

It is a known issue, but yes, currently we filter out maps to avoid the
scenario where a map is bound to an association. However, we should only be
doing this is if the target property is a domain class not if it is a map. I
believe there is already a JIRA for this.. will try dig it up

Cheers

--
Graeme Rocher

On Thursday, February 23, 2012 at 4:07 PM, Brian Saville wrote:
This is less of a problem and more of a question to see if anyone knows
where it comes from.  I’ve been using the binding pattern of the implicit
constructor or setting of properties:

def obj = new MyClass(params)
or
def obj = new MyClass()
obj.properties = params

But I noticed that when I upgraded to grails 2.0.1 (I’m sure this is more
internal to groovy itself), my properties that are Maps are no longer
binding correctly.  I have not tested whether bindData has this same issue.
So for an example domain class:

class MyClass {
                Map myMap
}

Then if try to create the object like this:

def obj = new MyClass(myMap:[test:true])
assert obj.myMap.test

This will fail.  Just curious if anyone knows about this or has any input on
something I might be doing wrong.

Thanks,
Brian


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Binding with Map properties

Graeme Rocher-2
The constructor is modified to bind and convert parameters yes

-- 
Graeme Rocher

On Thursday, February 23, 2012 at 4:34 PM, Brian Saville wrote:

They are simple maps – in fact since we use mongo, we don’t have any
restrictions on the contents of the map (ie string->string). But they are
definitely not domain classes. I thought the implicit constructor was a
property of groovy itself and not of grails, or do you modify the default
behavior?

I’d love the ticket if you can find it – I’ve tried searching multiple times
but haven’t come up with anything.

Thanks!
-Brian

From: Graeme Rocher [[hidden email]]
Sent: Thursday, February 23, 2012 8:21 AM
Subject: Re: [grails-user] Binding with Map properties

It is a known issue, but yes, currently we filter out maps to avoid the
scenario where a map is bound to an association. However, we should only be
doing this is if the target property is a domain class not if it is a map. I
believe there is already a JIRA for this.. will try dig it up

Cheers

--
Graeme Rocher

On Thursday, February 23, 2012 at 4:07 PM, Brian Saville wrote:
This is less of a problem and more of a question to see if anyone knows
where it comes from. I’ve been using the binding pattern of the implicit
constructor or setting of properties:

def obj = new MyClass(params)
or
def obj = new MyClass()
obj.properties = params

But I noticed that when I upgraded to grails 2.0.1 (I’m sure this is more
internal to groovy itself), my properties that are Maps are no longer
binding correctly. I have not tested whether bindData has this same issue.
So for an example domain class:

class MyClass {
Map myMap
}

Then if try to create the object like this:

def obj = new MyClass(myMap:[test:true])
assert obj.myMap.test

This will fail. Just curious if anyone knows about this or has any input on
something I might be doing wrong.

Thanks,
Brian


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


Loading...