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.