
ADF 11g: That is one very smart toolbarbutton !
There are situations where you need a toolbar to provide the user with functionality like insert, update, delete, next, previous and so on. This looks straightforward, but it is not that easy to have only one toolbar to service your whole page. In this post I will show an example of how to implement such a toolbar. I will create a single button that can do an insert on multiple different components. Let’s start with showing how you would usually create insert functionality; a simple example.
The examples in this post are based on default ADF BC from the HR employee and department tables. First we create a page with only one table component. The table is based on the Departments iterator. We also add a button to create a new row. This can be achieved by dropping the createInsert operation from the datacontrol palette onto the page. If you run the page and push the button, a new row is created in the table.

That was easy.
Now let’s make it more complicated.
We create a second table. This one is based on the Employees iterator. Now we actually want to use the same button to insert a row into this table. This is, of course, not possible because the button is designed to insert a row into the Departments iterator.
that can be used to insert a row in the departments table or in a different table ?
Actually we can do that. We need to figure out a couple of things to create such functionality.
Second we need to create a method to invoke programmatic insert.
Lets start with the first part.
What is the table that needs the new row ?
In this use case, it is in fact the ‘active’ table, or in other words, the table that currently has focus, or even better, the table that we just clicked on. An component has a selectionListener attribute. Usually the standard selection listener is used.
selectionListener="#{bindings.DepartmentsView1.collectionModel.makeCurrent}"
To find out the table that currently has focus we will have to implement a custom table selectionListener that will:
1) set the current row as soon as the user clicks on it (which is more or less default behavior).
2) extend that with functionality to tell the application what the currently active table is.
All this is coded in a newly created bean.

selectionListener="#{pageFlowScope.twoTablesBean.makeSelectionAndSetActiveTable}"
Because the selectionListener uses a SelectionEvent to ‘do its thing’ We can use the same selectionListener for both tables (and any others that you might think of). Based on the SelectionEvent, we can find the table that is associated with the event.
From there we can get to the iterator associated with the table, and set it’s current row.
public void makeSelectionAndSetActiveTable(SelectionEvent selectionEvent) {
// Thanks to Frank Nimphius
RichTable _table = (RichTable)selectionEvent.getSource();
//the Collection Model is the object that provides the structured data
//for the table to render
CollectionModel _tableModel = (CollectionModel)_table.getValue();
//the ADF object that implements the CollectionModel is JUCtrlHierBinding. It
//is wrapped by the CollectionModel API
JUCtrlHierBinding _adfTableBinding =
(JUCtrlHierBinding)_tableModel.getWrappedData();
//Acess the ADF iterator binding that is used with ADF table binding
DCIteratorBinding _tableIteratorBinding =
_adfTableBinding.getDCIteratorBinding();
Object _selectedRowData = _table.getSelectedRowData();
//cast to JUCtrlHierNodeBinding, which is the ADF object that represents
//a row
JUCtrlHierNodeBinding _nodeBinding =
(JUCtrlHierNodeBinding)_selectedRowData;
//get the row key from the node binding and set it as the current row in the
//iterator
Key _rwKey = _nodeBinding.getRowKey();
_tableIteratorBinding.setCurrentRowWithKey(_rwKey.toStringFormat(true));
}
Now that we know what iterator is associated with the selected table (the active table), we need to store this value in a variable.
This variable to hold the value of the current iterator, is created in the TwoTablesBean and is of the type DCIteratorBinding.
DCIteratorBinding theCurrentOne;
public void setTheCurrentOne(DCIteratorBinding theCurrentOne) {
this.theCurrentOne = theCurrentOne;
}
public DCIteratorBinding getTheCurrentOne() {
return theCurrentOne;
}
Now add code in the makeSelectionAndSetActiveTable method to set the value of this variable.
public void makeSelectionAndSetActiveTable(SelectionEvent selectionEvent) {
.........
setTheCurrentOne(_tableIteratorBinding);
}
The selectionListener is working, the current table is known so all is in place to implement the insert functionality.
The final step.
Create a button, with an associated actionListener, and code in the actionListener to perform a programmatic insert.
<af:commandToolbarButton text="insert" id="cb1" partialSubmit="true"
actionListener="#{pageFlowScope.twoTablesBean.createRecord}"/>
This insert action will not be performed on the operationbinding in the bindingcontainer, but we will use a programmatic insert. This is done by invoking createRow() on an iterator. The iterator that the createRow() will be invoked on is the iterator that is stored in the theCurrentOne variable. With invoking the getter on theCurrentOne we can retrieve this iterator, and create a new row.
public void createRecord(ActionEvent evt) {
DCIteratorBinding it = getTheCurrentOne();
Row rw = it.getNavigatableRowIterator().createRow();
rw.setNewRowState(Row.STATUS_INITIALIZED);
it.getNavigatableRowIterator().insertRow(rw);
refreshUpdatedTable(evt);
}
And now it works ! We have one button that can insert both Departments and Employees.

You can continue to add buttons to edit/delete/save and more if you like.
Extra
One more example I’ll provide here is to add edit functionality in a popup window.
It is pretty straightforward because we can use ‘theCurrentOne’ to determine what popup to show.
<af:commandToolbarButton text="edit" id="cb2" partialSubmit="true">
<af:showPopupBehavior popupId="#{pageFlowScope.twoTablesBean.theCurrentOne.name}"
triggerType="click" partialTrigger="md1 t1" />
</af:commandToolbarButton>
<af:popup id="EmpIt"
contentDelivery="lazyUncached">
<af:dialog id="d3" type="okCancel" title="Edit #{pageFlowScope.twoTablesBean.theCurrentOne.name}" resize="on">
<af:panelFormLayout id="pfl3">
.........................
</af:panelFormLayout>
</af:dialog>
</af:popup>
<af:popup id="DepIt"
contentDelivery="lazyUncached">
<af:dialog id="d2" type="okCancel" title="Edit #{pageFlowScope.twoTablesBean.theCurrentOne.name}" resize="on">
<af:panelFormLayout id="pfl2">
.........................
</af:panelFormLayout>
</af:dialog>
</af:popup>
I found that theCurrentOne variable must have a default value (or an if null construct). If not, the page will not function properly because popupId=”#{pageFlowScope.twoTablesBean.theCurrentOne.name}” cannot be resolved. Once I figured this out, the rest was pretty straightforward.
In the corresponding popup, you show the either departments ……

…… or employees to edit.

Resources
Frank Nimphius about selection listener
Andrejus Baranovskis about crud operations in tables
ADF 11g : Query Component with ‘dynamic’ view criteria
18/10/2011 - 10:00 pm
Tags: adf 11g, dynamic, luc bors, query component, taskflow
Posted in ADF & JHeadstart, Oracle Development Tools | No comments
In my current project use a lot of re usable taskflows. In one particular situation I needed exactly the same taskflow to be re-used with one tiny small difference: The displayed query component needed to have different fields compared to page in the base taskflow. Now there are lots of possible solutions (two query components [...]
ADF 11g Rich Faces: using popup for viewing and editing big fields
5/10/2011 - 3:08 pm
Tags: adf, adf 11g, forms modernization, popup
Posted in ADF & JHeadstart, Java, JEE, OAS and WebLogic Server, Oracle | 3 comments
During the Oracle Open World conference going on this week I was asked by one of the attendees to one of my sessions for a little guidance on the following challenge in ADF:
“We currently have an Oracle Forms application that we are rebuilding in ADF 11g. One of the features in this Forms application, is [...]
ADF 11g R2 : Using the ActiveRowKey property
31/8/2011 - 8:55 pm
Tags: activeRowKey, adf 11g, luc bors, selectionListener
Posted in ADF & JHeadstart, General, Oracle Development Tools, Software Engineering, Technical Architecture, Web/Java | No comments
In ADF 11g Release 2, the ADF Table component has a property called ‘ActiveRowKey’. According to documentation, this represents the row that is currently active on the client. In click-to-edit mode, the active row will be made editable and is brought into view (if not already visible). Upon initial display, the click-to-edit component defaults the [...]
ADF 11g : Show PDF in a Popup
28/7/2011 - 9:35 pm
Tags: adf 11g, inline frame, luc bors, pdf, popup, servlet
Posted in ADF & JHeadstart, AMIS, General, Oracle, Web/Java | 3 comments
In one of my previous posts I showed how to use ADF popup components to display external content such as webpages like wikipedia in an inline frame. Based on this post a colleague of mine tried to display a PDF document. That didn’t work. In this post I explain how you can use a servlet [...]
ADF 11g : Printing Directly From Your Application
26/7/2011 - 8:07 pm
Tags: adf 11g, java print, javax.print, luc bors, print API, printing
Posted in ADF & JHeadstart, AMIS, General, Java | No comments
Last week I was asked this question : “Can we print directly from within our ADF Application, without invoking the printer dialog ?” I wasn’t sure but after some investigation the answer was clear. Yes you can ! Here is how
I decided to create a print start up form where I can select printers [...]
ODTUG KScope 11 : A short overview of ADF on the Fusion Middleware track
25/7/2011 - 8:12 pm
Tags: adf, kscope 2011, luc bors, ODTUG
Posted in AMIS, General | No comments
From June 26th to June 30th the KScope 11 conference was in Long Beach California. Nice setting for a great conference. It was the first time that KScope had a Fusion Middleware Track. For me it was a very busy conference with three presentations, handson workshops, live demonstrations and a Boff session with the EMG. [...]
Book review: JDeveloper 11g Handbook: A Guide to Fusion Web Development
21/7/2011 - 11:31 am
Tags: adf 11g, jdeveloper 11g, task flow
Posted in General, J(2)EE/Java, Java, JEE, OAS and WebLogic Server, Oracle, Web/Java | 1 comment
In this blog I will share with you my experiences with the Oracle JDeveloper11g Handbook – A Guide to Oracle Fusion Web Development (McGraw-Hill, 2010) – written by Duncan Mills, Peter Koletzke and Avrom Roy-Faderman. It is the successor of their previous book, JDeveloper 10g for Forms & PL/SQL Developers. This is a book to [...]
KSCOPE 2011: Keynote & Award Recognition
30/6/2011 - 7:41 pm
Tags: Alex nuijten, Award, kaleidoscope 2011, luc bors
Posted in ADF & JHeadstart, AMIS, Java, JEE, OAS and WebLogic Server, SOA & Oracle Fusion Middleware, Software Development | No comments
While the congrats are getting in via the usual virtual channels like Twitter and mail for being awarded the best speaker awards for the Database (Alex Nuijten) and Fusion Middleware (Luc Bors) tracks, I would like to mention that great Keynote session on Monday that was put together by the ODTUG Kaleidoscope board. The board [...]
ADF 11g R2 : ADF Business Components UI Categories and Dynamic Forms (and some new IDE features)
7/6/2011 - 11:08 pm
Tags: adf 11gR2, dynamic form, jdeveloper, jdeveloper 11g, luc bors, UI Categories
Posted in ADF & JHeadstart, AMIS, Oracle, Oracle Development Tools | No comments
ADF 11gR2 has some very nice UI Hints features. Some were already available in previous releases. In this post I will describe the effect of the UI Categories. On the go, I will also point out some other new features. To see how this works, I created simple ADF Business Components from tables (That is, [...]
ADF 11g R2 : Skin Editor First Impressions
7/6/2011 - 8:34 pm
Tags: 11gr2, adf, adf 11gR2, css, jdeveloper 11g, luc bors, skin editor, skineditor
Posted in ADF & JHeadstart, Devel. + PL/SQL tools, General, Oracle, Oracle Development Tools, Web/Java | No comments
With JDeveloper 11gR2 the skineditor is finally there. I share my first impressions in this post. When you need a skin for your application in previous versions, some configuration was needed. With 11gR2 it is much easier.
So what are the skinning features included in 11gR2 and in the skin editor ? The new JDeveloper editor [...]


29/9/2011 - 5:27 pm
Hi,
Can you please give us code sample how to handle when we have one table with formlayout and one with adf table?
regards
murali