You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by Ritz123 <ri...@gmail.com> on 2008/04/09 20:03:02 UTC

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-tp16592940p16592940.html
Sent from the OFBiz - User mailing list archive at Nabble.com.


Re: GenericValue without field checking

Posted by Adrian Crum <ad...@hlmksw.com>.
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: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
>>
>>
>>
> 

RE: GenericValue without field checking

Posted by "skip@thedevers" <sk...@thedevers.org>.
Dozens of ways to skin a cat.  Sounds like you have considered all of them.

Skip

-----Original Message-----
From: Ritz123 [mailto:ritesh.trivedi@gmail.com]
Sent: Wednesday, April 09, 2008 11:53 AM
To: user@ofbiz.apache.org
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: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
>
>
>

--
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


RE: GenericValue without field checking

Posted by Ritz123 <ri...@gmail.com>.
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
> 
> 
> 

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


RE: GenericValue without field checking

Posted by "skip@thedevers" <sk...@thedevers.org>.
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