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:
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.