Dive into Oracle ADF

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 9:11:55 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Search blog with Google:
 

Search BC4J JavaDoc:
 

January 2004
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Dec   Feb

Get Firefox!

Thursday, January 29, 2004

One of the little "gotchas" that I ran into while upgrading the BC4J Toy Store Demo to JDeveloper 10g and the ADF Binding layer is that ADF iterator bindings (whose role it is to act as "middlemen" between the view/UI layer and the collections of data surfaced by business services to the model layer) always like to have some row be the current row in a row set. That is, they do not like the "current row" to be the slot before the first row, or the slot after the last row. I ran into a problem where my business logic that was calculating the total of the items ordered in the shopping cart was always skipping over the first item in the cart. The problem was that my middle-tier calculation should not have been using the default iterator on the rowset of shopping cart items, since that is the iterator that the user interface layer will use. I modified the code to create a secondary iterator (which will not be involved in the user-interface layer's notion of what the "current" row is) and produced a slightly modified calculation routine like this:

/** [From ShoppingCartImpl.java, a ViewObjectImpl subclass ]**
 * Returns the total cost of all items in the cart
 */
public double cartTotal() {
  double total = 0;
/* Passing null for iterator name will assign a system-generated name */
  RowSetIterator cartItems = createRowSetIterator(null);
  while (cartItems.hasNext()) {
    ShoppingCartRowImpl curItem = (ShoppingCartRowImpl)cartItems.next();
    total += curItem.getExtendedTotal().doubleValue();
  }
  cartItems.closeRowSetIterator();
  return total;
}

Notice that I create the additional iterator using the createRowSetIterator() method. This can be called on any row set, but here inside of my view object implementation class, the above method call will delegate the call to the view object's default rowset. Also note that iterators in BC4J are named and are designed so that you can find them by name later in your session. If you pass a string name to the createRowSetIterator() method, we'll use your name. If you pass null, we'll generate a name for you. If needed, you can always find out the name of the iterator by calling its getName() method. In this case, I only need the secondary iterator for the moment in time that I'm performing the calculation, so I call closeRowSetIterator() on it when I'm done with it to remove it.


11:46:16 AM    



© Copyright 2008 Steve Muench.