Dependent LOV (SelectOneChoice) for country state exmplae in ADF

Hi All,

Today I am going to show how you can create the dependent LOV in ADF.

Suppose for example we are taking countries and states LOV example. So whenever you change the country in LOV the states SelectOneChoice should show the valid states for that particular selected country.

To demonstrate this I have created some tables and insert some value in those tables.
You table should have something relationship like this only..

create table country (
country_id number(8,0),
state varchar2(10)
);


insert into country values (1, 'BNG');
insert into country values (2, 'TX');
insert into country values (3, 'LON');
insert into country values (4, 'SDY');
insert into country values (5, 'CGG');


create table state_name(
state_id varchar2(10),
state_name varchar2(2000),
country_id number(8,0)
);



insert into state_name values ('BNG', 'Bangalore', 1);
insert into state_name values ('DEL', 'Delhi', 1);
insert into state_name values ('KOL', 'Kolkata', 1);
insert into state_name values ('MUM', 'Mumbai', 1);
insert into state_name values ('MAS', 'Chennai', 1);

insert into state_name values ('WA', 'Washington', 2);
insert into state_name values ('OK', 'Oklahoma City', 2);
insert into state_name values ('DNV', 'Denver', 2);
insert into state_name values ('TX', 'Texas', 2);
insert into state_name values ('UT', 'Utah', 2);

insert into state_name values ('LON', 'London', 3);
insert into state_name values ('BGM', 'Birmingham', 3);
insert into state_name values ('LIV', 'Liverpool', 3);
insert into state_name values ('MAN', 'Manchester', 3);

insert into state_name values ('CANB', 'Canberra', 4);
insert into state_name values ('SDY', 'Sydney', 4);
insert into state_name values ('MLB', 'Melbourne', 4);
insert into state_name values ('PRTH', 'Perth', 4);

insert into state_name values ('BJG', 'Beijing', 5);
insert into state_name values ('CGG', 'Chongqing', 5);


Now we will create a ADF application to show the countries and states as dependent LOV.

After creating new Application just do a right click on Model project and select option "New".


Now select "ADF Business Component" from category block and select "Business Component From Tables".


Now select the Country table and provide te Entity Name and click on "Next".


Now select the Entity Object and give the View Object name according to your wish and then click on "Next".


Click on "Next" because right now I don't want to create any Read Only View Object.
The creation of Read only View Object we will see seperately in this post only.


Select the check box Application Module as it is not there so we need to create it. After this click on "Next".



Click on "Next" as I don't want to create Business Component Diagram.


Click on "Finish" Button.


Now go to "New Gallary" and select the option to create new view object.
Here we are going to create read only view object.


In the next screen just provide the name of your read only view object and select the option "Read only access through SQL only". This we are creating country names view object which we will attach as LOV in CountryId attribute of CountryVO.


Provide the SQL query to fetch all the information related to country and click on Next.


Click on Next.


 In this screen just check if your mapping is correct or not and then click on "Next".


Click on "Next".


Click on Next.


Click on Next as we don't want to generate the ViewObjectImpl and Def classes.


Click on "Next".


Click on "Finish" in order to finish the creation of Read Only View Object.


As we have created the CountryRO in same way we have to create StateNamesRO.
But in the creation of StateNamesRO there is slight difference. The difference is, it will have one where clause in the query based on country_id column.


Click on "New" option in below screen and then give the bind variable name here which we have given in last step.

One thing you have to be careful here that "Required" property should be checked.
 

Now keep clicking on "Next" until you get to the last screen. Then on last screen you just click on "Finish" to finish the creation of StateNamesRO.


Now you should have three View Object after all steps and one Application Module.


Now go to CountryVO and select CountryId attribute and then Click on Add icon of "List Of Values:CountryId".


In this screen just select the source of the LOV by clicking on Add icon as shown below. In our case the source of LOV is CountryRO.


Here we will shuffle the CountryRO to right and click on "Ok".


Now select CountryId from CountryRO LOV and map it to the CountryId of  CountryVO.


Then your screen will look like this.


Now Shuffle the  CountryName from left box to right box as shown below in the screenshot.

And click on "Do not include blank selection item" and click on "Ok".


Now select the State attribute fron CountryVO and add the LOV as we have done before for CountryId.


Select the StateNamesRO to the right and click on "Ok".


Select the StateId which we need to store to database.


Now select the StateName and shuffle if to the right and also uncheck the checkbox for "Include blank selected Item". Now click on "Ok".


Now go to ViewAccessor option of CountryRO and select StateNamesRO and click on Edit icon.


Specify the value of the bind variable as attribute name of CountryId.

Because whatever country we will select the id of that country we will pass to the StateNamesRO.

So that it will show the states related to that country only.


Now edit the CountryId attribute and go to control hints option and set Auto Submit property to true and click on "Ok".


Now open State attribute to edit and click on Dependencies option and shuffle the CountryId on right and click on "OK".


Now Run your Application Module you will see the states corresponding to selected country only.


That's all about from my side about dependent LOV or SelectOneChoice.

Happy Coding :)

Comments

  1. Your post was too good for beginners. but in the country table country name is missing.

    ReplyDelete

Post a Comment

Popular posts from this blog

Setting up the environment for Angular2 and Hello World Example in Angular2

Showing number of rows or row count on top and bottom of table in ADF.

Build a Simple ReactJS application using react-cli