Saturday, February 11, 2012

Many-to-Many Relationship Insert in ADF BC and ADF Faces UI

My last post was about how to implement Many-to-Many relationship in ADF BC and ADF UI - Many-to-Many Relationship Implementation in ADF BC and ADF Faces UI. I will continue the same topic and describe today how to implement Insert operation for Many-to-Many relationship.

Download developed sample application - This sample is update for previous blog post application. It contains code to insert new records into Many-to-Many relationship.

There is Java method in Application Module implementation class, it inserts mapping row into relationship table (BlogsReaders) and commits transaction - this method is called from ViewController, after user submits new row for insert. Readers and Blogs VO's are refreshed after insert - to bring new mapping back to the UI:

I have defined two additional VO instances in Application Module for both ends (Blogs and Readers). This is required for better UI experience - while inserting new record, current records will stay in tact:

Managed Bean from ViewController contains two listeners - one to insert blank row and prepare data entry form, another is triggered when users confirms new record - it retrieves required ID mapping and calls method from Application Module to populate mapping table and complete transaction. This example is for Readers end, same is applied for Blogs end:

ADF binding view - 4 iterators to represent Many-to-Many relationship and 2 iterators for data entry:

On runtime it works like that - user adds new reader, data entry popup opens. New  reader entry is automatically associated with currently selected blog:

New reader - Sheldon is inserted, right side with related blog can be synched for new record:

In the same way, we can insert new blog:

Now user is reading two blogs:

If you will change a reader on the right side to Julia, blog list will be updated. However, if you would like to synch all readers from selected blog - click on blog row or press Synch button:

Readers list is in synch:


Vinay Agarwal said...

Hi, would you like taking a look at my post on the same lines?

Andrejus Baranovskis said...


Nice, it seems a bit different approach - you are using checkbox.

In my next posts I will post delete and edit - quite easy.


Nishant said...

Hi Andrejus,

Have you posted the delete and edit tutorials? Couldn't find them.

Suman said...

Hi Andrejus,

I have the same requirement. But the primary key will be coming from DBSequence (These keys will be generated at the database level after commit). How can we handle this case ? Can you help me with this ?

Anonymous said...

Hi Andrej,
We have a similar requirement, with create insert on both tables at the same time, with primary keys generated by dbsequence.
Any suggestions on how to get going with this?

Habib Eslami said...

Hi Andrejus. Thanks for your helpful posts about ADF.
I have a similar use case, but I need to show the intersection VO and this VO should be synch with navigating between blogs rows or readers rows. Is it any way to do this?