normally you use a view-entity.
this lets you group entities and chose the fields you want
then you query the view-entity like any other.
Like in Databases, you must have all the relationships satisfied for any
row you want to display.
Note you can build a view-entity on the fly, but for debug purposes, I
use the xml version so I can see the results in the web tools.
I like this method of queries
using findList
and
EntityCondition.makeCondition(exprs,
                            EntityOperator.AND
you can find examples of this.


madppiper sent the following on 12/4/2008 4:02 AM:
> Alright,
> 
> this is driving me insane, and after searching all through the available
> ofbiz screens and beanshell files, I would really appreciate some help on
> this. 
> 
> All I want to do is to retrieve a sample of four products (randomly
> selected) that contains the description, title, price, listprice, productId
> and brandName, so that I can access the information via ftl later on and
> display 4 productboxes...
> 
> I got the first part together just fine: 
> 
> /*Find Products*/
> delegator = request.getAttribute("delegator");
> products = delegator.findAll("Product");
> productShowLimit=4;
> 
> 
> 
> 
> //now slim it down to promoShowLimit
> productArrayList = new ArrayList(products);
> 
> productPromos = null;
> if (productArrayList.size() > productShowLimit) {
>     productPromos = new ArrayList(productShowLimit);
>     for (i = 0; i < productShowLimit; i++) {
>         
>             randomIndex = Math.round(java.lang.Math.random() *
> (productArrayList.size() - 1));
>         
>         
> 
>         productPromos.add(productArrayList.get((int) randomIndex));
>     }
> 
> } else {
>     productPromos = productArray;
> }
> 
> 
> But I cannot get my head around on how to link this information to the
> listPrice... getRelatedOne on ProductPrice retrieves all the prices for a
> certain product: 
> 
> productPrices = null;
> Iterator p = productPromos.iterator();
> while(p.hasNext()){
>  GenericValue p = (GenericValue) p.next();
>  prices = p.getRelated("ProductPrice");
>  System.out.println("Out: "+  prices);   
> }
> 
> 
> But i cannot combine that information with the previous resultMap
> (productPromos )...  Also, I've read on 
> 
> http://www.opensourcestrategies.com/ofbiz/ofbiz_entity_cookbook.txt
> 
> that you shouldn't access the product data table directly (which makes
> sense), and so I can't help but wonder on whether there are easier/already
> existing ways of what I am trying to accomplish...

Reply via email to