« March 6, 2007 | Main | April 16, 2007 »

April 10, 2007 Archives

April 10, 2007

ADF Binding 10.1.3.x: Clearing the input values

Today, I was facing a surpring problem with my ADF application.

My application contains a number of pages for creating new entries in a database (I call them "create" pages). This sounds like a common usage and it is. The interesting part showed up when I called the "create" page again (after doing some other stuff in the application).

The "create" page was not an empty page as expected, but had the values previously entered to create a new entry. This is quite handy for testing but unintentional.

The hint for the solution came from Frank Nimphius:

In an actionListener for the "Create" button do something like this:
FacesCtrlAttrsBinding o =
  (FacesCtrlAttrsBinding)bindings.get("nameSrch");
o.setInputValue("%");


Although this sounds fairly easy, it becomes quite tedious for many different pages.

Digging deeper in the ADF Binding API, I found the generic solution:

protected void resetForm(BindingContainer bindings) {
  List l = bindings.getAttributeBindings();
  for (Iterator it = l.iterator(); it.hasNext();) {
    Object o = it.next();
    if (o != null) {
      if (o instanceof FacesCtrlAttrsBinding) {
        ((FacesCtrlAttrsBinding)o).setInputValue(null);
      }
    }
  }
}


Calling this method in your Action Listener just before you return the desired outcome will do the trick.

About April 2007

This page contains all entries posted to Olaf Heimburger's Blog in April 2007. They are listed from oldest to newest.

March 6, 2007 is the previous archive.

April 16, 2007 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle