GenericValue without field checking

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

GenericValue without field checking

Ritesh Trivedi
Hi,

I have a usecase where I need to store additional fields (which are actually not in the table) for Product in GenericValue. Current implementation of Entity engine doesnt seem like it supports it.

Does anyone know of a way around? e.g. I would like to add couple of fake fields to Product entity like Brief Description, Marketing Description but dont want to worry about persisting it - just want to be able to "put" them in the genericvalue and then access it in the page.

I know one way would be to create a map (like context and put legal GenericValue product and those additional fields in the map - I am looking to see if it can be done just by using GenericValue itself and not additional objects.

Thanks
Reply | Threaded
Open this post in threaded view
|

RE: GenericValue without field checking

SkipDever
Ritz

The map thing you describe works a charm.  I've done it myself lots.  You
can make lists of these maps and pass them to your display code just as you
would a list of GenericValues.

GenericEntity (on which GenericValue is derived) has code to check if the
field exists when you call put() on it, so you have to build one from
scratch if you want to use as you want.  GenericValue may also in some cases
be immutable.  Much simpler to use a Map.

Then you can use map.putAll(genericValue)

If you insist on using GenericValue, there is a
GenericValue.create(ModelEntity modelEntity, Map fields) that would work for
you.

Skip


-----Original Message-----
From: Ritz123 [mailto:[hidden email]]
Sent: Wednesday, April 09, 2008 11:03 AM
To: [hidden email]
Subject: GenericValue without field checking



Hi,

I have a usecase where I need to store additional fields (which are actually
not in the table) for Product in GenericValue. Current implementation of
Entity engine doesnt seem like it supports it.

Does anyone know of a way around? e.g. I would like to add couple of fake
fields to Product entity like Brief Description, Marketing Description but
dont want to worry about persisting it - just want to be able to "put" them
in the genericvalue and then access it in the page.

I know one way would be to create a map (like context and put legal
GenericValue product and those additional fields in the map - I am looking
to see if it can be done just by using GenericValue itself and not
additional objects.

Thanks
--
View this message in context:
http://www.nabble.com/GenericValue-without-field-checking-tp16592940p1659294
0.html
Sent from the OFBiz - User mailing list archive at Nabble.com.


No virus found in this incoming message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
8:23 AM

No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
8:23 AM

Reply | Threaded
Open this post in threaded view
|

RE: GenericValue without field checking

Ritesh Trivedi
Skip,

Thanks for the response.

Creating a Map would be one way to do it - since anyway GenericValues are Maps under the hood. The other ways would be to create GenericValueEx extending GenericValue and overriding get and put methods catching exception and storing those fields in another map inside the derived class. or use containment pattern and have GenericValue as contained object with in GenericValueEx and add GenericValue methods as and when needed to the derived class.

>If you insist on using GenericValue, there is a
>GenericValue.create(ModelEntity modelEntity, Map fields) that would work for you.
Even that throws IllegalArgumentException - at least from the code thats what it seems like. The only method that does NOT throw the exception but ignores additional values is makeValidValue() from delegator.

skip@theDevers wrote
Ritz

The map thing you describe works a charm.  I've done it myself lots.  You
can make lists of these maps and pass them to your display code just as you
would a list of GenericValues.

GenericEntity (on which GenericValue is derived) has code to check if the
field exists when you call put() on it, so you have to build one from
scratch if you want to use as you want.  GenericValue may also in some cases
be immutable.  Much simpler to use a Map.

Then you can use map.putAll(genericValue)

If you insist on using GenericValue, there is a
GenericValue.create(ModelEntity modelEntity, Map fields) that would work for
you.

Skip


-----Original Message-----
From: Ritz123 [mailto:ritesh.trivedi@gmail.com]
Sent: Wednesday, April 09, 2008 11:03 AM
To: user@ofbiz.apache.org
Subject: GenericValue without field checking



Hi,

I have a usecase where I need to store additional fields (which are actually
not in the table) for Product in GenericValue. Current implementation of
Entity engine doesnt seem like it supports it.

Does anyone know of a way around? e.g. I would like to add couple of fake
fields to Product entity like Brief Description, Marketing Description but
dont want to worry about persisting it - just want to be able to "put" them
in the genericvalue and then access it in the page.

I know one way would be to create a map (like context and put legal
GenericValue product and those additional fields in the map - I am looking
to see if it can be done just by using GenericValue itself and not
additional objects.

Thanks
--
View this message in context:
http://www.nabble.com/GenericValue-without-field-checking-tp16592940p1659294
0.html
Sent from the OFBiz - User mailing list archive at Nabble.com.


No virus found in this incoming message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
8:23 AM

No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
8:23 AM
Reply | Threaded
Open this post in threaded view
|

RE: GenericValue without field checking

SkipDever
Dozens of ways to skin a cat.  Sounds like you have considered all of them.

Skip

-----Original Message-----
From: Ritz123 [mailto:[hidden email]]
Sent: Wednesday, April 09, 2008 11:53 AM
To: [hidden email]
Subject: RE: GenericValue without field checking



Skip,

Thanks for the response.

Creating a Map would be one way to do it - since anyway GenericValues are
Maps under the hood. The other ways would be to create GenericValueEx
extending GenericValue and overriding get and put methods catching exception
and storing those fields in another map inside the derived class. or use
containment pattern and have GenericValue as contained object with in
GenericValueEx and add GenericValue methods as and when needed to the
derived class.

>If you insist on using GenericValue, there is a
>GenericValue.create(ModelEntity modelEntity, Map fields) that would work
for you.
Even that throws IllegalArgumentException - at least from the code thats
what it seems like. The only method that does NOT throw the exception but
ignores additional values is makeValidValue() from delegator.


skip@theDevers wrote:

>
> Ritz
>
> The map thing you describe works a charm.  I've done it myself lots.  You
> can make lists of these maps and pass them to your display code just as
> you
> would a list of GenericValues.
>
> GenericEntity (on which GenericValue is derived) has code to check if the
> field exists when you call put() on it, so you have to build one from
> scratch if you want to use as you want.  GenericValue may also in some
> cases
> be immutable.  Much simpler to use a Map.
>
> Then you can use map.putAll(genericValue)
>
> If you insist on using GenericValue, there is a
> GenericValue.create(ModelEntity modelEntity, Map fields) that would work
> for
> you.
>
> Skip
>
>
> -----Original Message-----
> From: Ritz123 [mailto:[hidden email]]
> Sent: Wednesday, April 09, 2008 11:03 AM
> To: [hidden email]
> Subject: GenericValue without field checking
>
>
>
> Hi,
>
> I have a usecase where I need to store additional fields (which are
> actually
> not in the table) for Product in GenericValue. Current implementation of
> Entity engine doesnt seem like it supports it.
>
> Does anyone know of a way around? e.g. I would like to add couple of fake
> fields to Product entity like Brief Description, Marketing Description but
> dont want to worry about persisting it - just want to be able to "put"
> them
> in the genericvalue and then access it in the page.
>
> I know one way would be to create a map (like context and put legal
> GenericValue product and those additional fields in the map - I am looking
> to see if it can be done just by using GenericValue itself and not
> additional objects.
>
> Thanks
> --
> View this message in context:
>
http://www.nabble.com/GenericValue-without-field-checking-tp16592940p1659294

> 0.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
>
> No virus found in this incoming message.
> Checked by AVG.
> Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
> 8:23 AM
>
> No virus found in this outgoing message.
> Checked by AVG.
> Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
> 8:23 AM
>
>
>

--
View this message in context:
http://www.nabble.com/GenericValue-without-field-checking-tp16592940p1659388
4.html
Sent from the OFBiz - User mailing list archive at Nabble.com.


No virus found in this incoming message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
8:23 AM

No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
8:23 AM

Reply | Threaded
Open this post in threaded view
|

Re: GenericValue without field checking

Adrian Crum
In reply to this post by Ritesh Trivedi
Keep in mind that any custom classes you create will have to be
maintained. It would be preferable to follow Skip's suggestion.

-Adrian

Ritz123 wrote:

> Skip,
>
> Thanks for the response.
>
> Creating a Map would be one way to do it - since anyway GenericValues are
> Maps under the hood. The other ways would be to create GenericValueEx
> extending GenericValue and overriding get and put methods catching exception
> and storing those fields in another map inside the derived class. or use
> containment pattern and have GenericValue as contained object with in
> GenericValueEx and add GenericValue methods as and when needed to the
> derived class.
>
>> If you insist on using GenericValue, there is a
>> GenericValue.create(ModelEntity modelEntity, Map fields) that would work
> for you.
> Even that throws IllegalArgumentException - at least from the code thats
> what it seems like. The only method that does NOT throw the exception but
> ignores additional values is makeValidValue() from delegator.
>
>
> skip@theDevers wrote:
>> Ritz
>>
>> The map thing you describe works a charm.  I've done it myself lots.  You
>> can make lists of these maps and pass them to your display code just as
>> you
>> would a list of GenericValues.
>>
>> GenericEntity (on which GenericValue is derived) has code to check if the
>> field exists when you call put() on it, so you have to build one from
>> scratch if you want to use as you want.  GenericValue may also in some
>> cases
>> be immutable.  Much simpler to use a Map.
>>
>> Then you can use map.putAll(genericValue)
>>
>> If you insist on using GenericValue, there is a
>> GenericValue.create(ModelEntity modelEntity, Map fields) that would work
>> for
>> you.
>>
>> Skip
>>
>>
>> -----Original Message-----
>> From: Ritz123 [mailto:[hidden email]]
>> Sent: Wednesday, April 09, 2008 11:03 AM
>> To: [hidden email]
>> Subject: GenericValue without field checking
>>
>>
>>
>> Hi,
>>
>> I have a usecase where I need to store additional fields (which are
>> actually
>> not in the table) for Product in GenericValue. Current implementation of
>> Entity engine doesnt seem like it supports it.
>>
>> Does anyone know of a way around? e.g. I would like to add couple of fake
>> fields to Product entity like Brief Description, Marketing Description but
>> dont want to worry about persisting it - just want to be able to "put"
>> them
>> in the genericvalue and then access it in the page.
>>
>> I know one way would be to create a map (like context and put legal
>> GenericValue product and those additional fields in the map - I am looking
>> to see if it can be done just by using GenericValue itself and not
>> additional objects.
>>
>> Thanks
>> --
>> View this message in context:
>> http://www.nabble.com/GenericValue-without-field-checking-tp16592940p1659294
>> 0.html
>> Sent from the OFBiz - User mailing list archive at Nabble.com.
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG.
>> Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
>> 8:23 AM
>>
>> No virus found in this outgoing message.
>> Checked by AVG.
>> Version: 7.5.519 / Virus Database: 269.22.5/1359 - Release Date: 4/4/2008
>> 8:23 AM
>>
>>
>>
>