Quantcast

Retrieving user-defined properties from class

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

Retrieving user-defined properties from class

Eric Ettes
Hi all,

I was wondering how I can retrieve the properties of a command object. When I use theCommandObject.properties, I get everything that's inherited aswell like servletContext, grailsApplication etc., but I only need the properties that I've defined myself :-)

Kind regards,
Eric
---------------------------------------------------------------------
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
star

Re: Retrieving user-defined properties from class

tomas lin
Could you not define an empty command object and subtract it's
properties from yours?

i.e,

myCommandObject.properties - emptyCommandObject.properties

On Fri, Jul 27, 2012 at 1:54 PM, Eric Ettes <[hidden email]> wrote:

> Hi all,
>
> I was wondering how I can retrieve the properties of a command object. When I use theCommandObject.properties, I get everything that's inherited aswell like servletContext, grailsApplication etc., but I only need the properties that I've defined myself :-)
>
> Kind regards,
> Eric
> ---------------------------------------------------------------------
> 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


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

Re: Retrieving user-defined properties from class

Eric Ettes
Hi Tomas,

Just gave it a go, and it works, though it feels a bit of a hack to need an empty class in order to get what I need ;-)

This is how it works using your solution:


class MyCommand {
  def property1
  def property2
}

class EmptyCommand { }

----

def doSomething(MyCommand myCommand) {

  if(!myCommand.hasErrors()) {
    def properties = myCommand.properties - (new EmptyCommand().properties)
  }

}


I tried to find which class the command object inherits its default methods from, but I couldn't find that. It would be a bit nicer to use something like myCommand.properties - groovy.lang.SomeInterface.properties and drop the empty command altogether :-)

Kind regards,
Eric


On Jul 27, 2012, at 5:09 PM, Tomas Lin <[hidden email]> wrote:

> Could you not define an empty command object and subtract it's
> properties from yours?
>
> i.e,
>
> myCommandObject.properties - emptyCommandObject.properties
>
> On Fri, Jul 27, 2012 at 1:54 PM, Eric Ettes <[hidden email]> wrote:
>> Hi all,
>>
>> I was wondering how I can retrieve the properties of a command object. When I use theCommandObject.properties, I get everything that's inherited aswell like servletContext, grailsApplication etc., but I only need the properties that I've defined myself :-)
>>
>> Kind regards,
>> Eric
>> ---------------------------------------------------------------------
>> 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


Loading...