convert list of Generic value to Map

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

convert list of Generic value to Map

Vedam B
Hi,

Can some one help on "how to convert list of generic values returned using

findByConditionCache to a Map".



Regards

Vedam
Reply | Threaded
Open this post in threaded view
|

Re: convert list of Generic value to Map

Bilgin Ibryam
I can not guess any utility class doing this.
However you can iterated the list elements and put them to map one by
one. The key for an element in the Map could be its index of from the
List.

Bilgin

Reply | Threaded
Open this post in threaded view
|

RE: convert list of Generic value to Map

SkipDever
In reply to this post by Vedam B
Here's what I would do assuming the list is called productList and has a
productId in it and you wanted to map the list by productId:

FastMap returnMap = FastMap.newInstance();

for(int i = 0; i < productList.size(); i++)
{
        GenericValue product = (GenericValue)productList.get(i);
        returnMap.put(product.getString("productId", product);
}

Skip

-----Original Message-----
From: Vedam B [mailto:[hidden email]]
Sent: Wednesday, March 12, 2008 10:21 PM
To: [hidden email]
Subject: convert list of Generic value to Map


Hi,

Can some one help on "how to convert list of generic values returned using

findByConditionCache to a Map".



Regards

Vedam

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.518 / Virus Database: 269.21.7/1324 - Release Date: 3/10/2008
7:27 PM

No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.518 / Virus Database: 269.21.7/1324 - Release Date: 3/10/2008
7:27 PM

Reply | Threaded
Open this post in threaded view
|

Re: convert list of Generic value to Map

Vedam B
Thanks for your help.

I started learning ofbiz and trying to display selected fields from an
entity in form

For this, i have written the code like this

   1. Use findByConditionCache to get selected fields
      -

      List fieldUser = FastList.*newInstance*();

      fieldUser.add("userId");

      fieldUser.add("userName");

      EntityCondition userIdCond = *new* EntityExpr("userId",
      EntityOperator.*IN*, userIds);

      List userList = delegator.findByConditionCache("User",
      userIdCond, fieldUser, *null*);

Here i need to retrieve the userList and send as a Map which conains user
records - only userId & userName for matching user ids in userIds List.

Thanks for any help.

Regards
Vedam


 On Thu, Mar 13, 2008 at 11:52 AM, skip@thedevers <[hidden email]>
wrote:

> Here's what I would do assuming the list is called productList and has a
> productId in it and you wanted to map the list by productId:
>
> FastMap returnMap = FastMap.newInstance();
>
> for(int i = 0; i < productList.size(); i++)
> {
>        GenericValue product = (GenericValue)productList.get(i);
>        returnMap.put(product.getString("productId", product);
> }
>
> Skip
>
> -----Original Message-----
> From: Vedam B [mailto:[hidden email]]
> Sent: Wednesday, March 12, 2008 10:21 PM
> To: [hidden email]
> Subject: convert list of Generic value to Map
>
>
> Hi,
>
> Can some one help on "how to convert list of generic values returned using
>
> findByConditionCache to a Map".
>
>
>
> Regards
>
> Vedam
>
> No virus found in this incoming message.
> Checked by AVG.
> Version: 7.5.518 / Virus Database: 269.21.7/1324 - Release Date: 3/10/2008
> 7:27 PM
>
> No virus found in this outgoing message.
> Checked by AVG.
> Version: 7.5.518 / Virus Database: 269.21.7/1324 - Release Date: 3/10/2008
> 7:27 PM
>
>