Thursday, March 6, 2014

Quick Tip: Best Way to Loop Through View Object Rows Programatically

You may have noticed there are multiple ways to do one task in ADF in many situations. Especially once you get involved on the Java side of ADF. While there are multiple ways to do something, it doesnt mean all of them are necessarily the best.

One question, which can be fairly common among new ADF developers, whats the best way to programatically loop through a View object's rows without affecting the View Object's root RowSetIterator? After all, you have what seems to be too many ways to do this:
  • ViewObjectImpl.getAllRowsInRange, returning Row[]
  • ViewObjectImpl.getRowSet, returning RowSet
  • ViewObjectImpl.getRowSetIterator, returning RowSetIterator
  • ViewObjectImpl.createRowSetIterator, returning RowSetIterator
While all ways could work per the above, only one is the best, ViewObjectImpl.createRowSetIterator. It delivers the most consistent results and it won't affect the currently selected row of the View Object.

Here's how we use it:

  1. Create RowSetIterator from your View Object class: ViewObjectImpl.createRowSetIterator()
  2. Reset the RowSetIterator - just in case
  3. Loop through the iterator: while(RowSetIterator.hasNext()) { .. }
  4. After your loop is finished, close the RowSetIterator: RowSetIterator.closeRowSetIterator()

See this example, where i look up a view object row by attribute value:

public Row getRowByAttribute(ViewObjectImpl vo, String attributeName, Object attributeValue) {
RowSetIterator rsi = vo.createRowSetIterator(null);
rsi.reset();
Row currRow=null;
while(rsi.hasNext()) {
currRow = rsi.next();
if (currRow.getAttribute(attributeName).equals(attributeValue)) {
rsi.closeRowSetIterator();
return currRow;
}               
}
rsi.closeRowSetIterator();
return null;        
}

Happy JDeveloping!

A Better ADF Mobile Development Experience on Android

Silly me, i forgot to publish this post that i wrote back in August :)

ADF Mobile developers will relate to this when I say, the Android Emulator is the definition of "painful". A day in a typical life of an ADF Mobile developer working with Google's Android Emulator is:
Develop an app in JDeveloper. Start the deploy process. 7 minutes later the app is deployed - unless you use the release mode trick i showed you. Next, go to your emulator start the app launch process. And 10 minutes later you'll get to see your app... as you later realize you forgot to write a critical line of code - and you die a little bit inside.

Unless you intend on playing a game of cricket or grill hotdogs and hamburgers for your office during each deployment cycle, you're probably itching to get your hands on a more efficient emulator. This is your answer.

AndroVM or what it will later be called, Genymotion. Genymotion will be a commercialized version of AndroVM. AndroVM is a product which runs on Oracle's virtualization software, VirtualBox. While, this is not supported by ADF Mobile and has some shortcomings, as reported by ADF Product Manager Chris Muir, it definitely eases the pain of quickly testing code you write for your ADF Mobile application.   As a AndroVM user, I can testify that apps run wicked fast compared to the emulator. Below are steps on how you can get started with AndroVM and ADF Mobile.


  1. Download and Install Virtual Box. I installed version, 4.2.12.
    Download Link: https://www.virtualbox.org/wiki/Downloads
  2. Consult the AndroVM Documentation and download an AndroVM with gapps & houdini & flash.
    vbox86p VMs are built for Phones, 480x800 default resolution
    vbox86t VMs are built for tablets, 1024x600 default resolution
    vbox86tp VMs are tablets with phone capabilities, 1024x600 default resolution.
  3. Once the AndroVM is downloaded, double click on it to import your AndroVM into VirtualBox. I accept all the defaults.
  4. Before you start AndroVM, you need to update the Network Settings to allow the Android SDK to connect to the VM. Select your VM, click on Settings > Network > Adapter 1. Set the Attached To field to Host-only Adapter. Click OK.


  5. Startup the AndroVM
  6. Allow approximately a minute for Android to boot up.
  7. For the first time starting up Android, you'll be prompted to specify your android settings, as you normally would during an initial Android boot process.When you complete the first time configuration settings, your screen should look like the screen below. From here, you're ready to deploy apps onto AndroVM!
  8. From there you're ready to deploy apps onto the AndroVM!