Saturday, August 18, 2007

Create multiple rows in Oracle ADF

Recently I have noticed a question on OTN JDeveloper forum about how to create multiple rows in ADF Faces af:table component and insert those rows into database. Actually almost at the same time my friend asked me for help, her goal was to develop exactly the same functionality. So, it seems multiple inserts could be quite often requirement.

Developed sample application - CreateMultipleLocations.zip is based on LOCATIONS table from standard HR schema. Developed business logic allows to create several locations in specified city at once.

To make this sample more interesting, number of rows to create is specified in property file - Resources.properties. Property value available in this file is retrieved in backing bean method and specified number of rows is created respectively.

Sample application JSPX page is divided into two main areas - Panel Box and Table:


First part contains a form, this form allows to provide a city, where locations will be created. It is mandatory to provide a city name, before creating locations. What is most important - Create button for LocationsView1 is developed in the same way as it is described in my previous post - Creating new row using CreateInsert operation. In second part, editable table is created, this table allows to add and edit locations data.

I guess, you may wonder - where is a specific of multi insert. In fact, it is only in one place - in action method for Create button. Developed createButton_action() method:


In first line of this method, value from property file is retrieved. Based on retrieved value, one or multiple rows are created and inserted into View object.

Let's say we want to create several new locations in Vilnius city, so just provide city name and press Create:


Provide required data and press Save:


When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.

9 comments:

Anonymous said...

Is it not possible to do the transaction in one go so that theres only one commit done?

Andrej Baranovskij said...

Hi,

In developed sample, commit is done for at least 3 rows.

Regards,
Andrejus

Unknown said...

Hi Andrejus,

Thanks for this post.

But do you need to bind every html tag and adf faces tag to the bean?
And why is this?

regards,
Marcel

Rajesh Kanigolla said...

Hi,

If user wants to enter only 2 records then how this application will work. Is there any solution for such requirement.?

Rajesh Kanigolla said...

Hi,

If user wants to enter only 2 records in the given 3 open rows then how this application works. Is there any solution to achieve this functionality? Please help..

Josel said...

HI, I' am trying to insert multiples row from a adf table but didnt work. I try with BC and WS. Any advice

Unknown said...

Hi Andrejus,

Unable to access the project zip file. Could you provide the new url?

Thanks,
SB

Andrej Baranovskij said...

Check my post about old samples: https://andrejusb.blogspot.lt/2017/08/my-blog-samples-download-repository-for.html

Andrejus

Unknown said...

Thanks!!