How to create LOV in ADF 11g

Hi,

This week we will be learning how to create LOVs in Oracle ADF application.

Pre-requisites:
– HR Schema in Oracle database.
– I am using Jdeveloper 11.1.3

Objective:
On this post we will create LOV for Department Id in Simple Employee based form.

Steps to follow:

Adding Department Entity:

– Add Departments Entity by Right clicking on Vinay.model package in Model project and choose New Entity Object
Enter Name as ” Department ” and Choose Schema object as ” Department ” by pressing Browse button you can select from the list of objects as well.

Right click on Vinay.model.view package and Choose New View Object name Departments as below


Now we will be creating view object for Department

Uncheck the updatable checkbox.

Select department name and department id.in the order by clause use department ID.
Click next and finish it.Repeat the same step for Employee ViewObject.

Now we will be creating the lov . Double click Departmet view object.
– Select DepartmentId attribute in the attribute page and Click “+” green button at the bottom under List of Values section.

– Click the green + button with List Data Source.
A create List of value wizard will open.In the configuration tab click the + sign if there is no default value is there

On clicking of the ‘+’ sign a view accessor pop up will open.Select Department View Object and shuttle to right side.

In the list attribute select department ID.Click ok.Now your department View object would like as below

Now we will link Lov to the JSPX page.Click new on view controller project.And select jsf page.Give
File name LovPage.In

In the data control palette.Select department view which we created and drag drop on the page

A wizard will open.As you can see department Id is coming as select one choice

Now your jspx page look like this.

Click run on the page. In browser you can see department Id is coming as LOV.It is easy to create.If you want to create lov from another entity object then you need to have accessor on that referring entity object.And you will use that accessor in List Data source in configuration tab.

Different memory scope in Oracle ADF

Application: The application scope lasts until the application stops. Values that you store in a managed bean with this scope are available to every session and every request that uses the application.

session: The session scope begins when a user first accesses a page in the application and ends when the user’s session times out due to inactivity, or when the application invalidates the session.
The session scope begins when a user first accesses a page in the application and ends when the user’s session times out due to inactivity, or when the application invalidates the session. Use this scope only for information that is relevant to the whole session, such as user or context information. Avoid using it to pass values from one task flow to another. Instead, use parameters to pass values between task flows. Using parameters gives your task flow a clear contract with other task flows that call it
or are called by it. Another reason to avoid use of session scope is because it may persist beyond the life span of the task flow.

pageFlow: this is accessible across the activities within a task flow. A managed bean that has a pageFlow scope shares state with pages from the task flow that access it. A managed bean that has a pageFlow scope exists for the life span of the task flow.If another task flow’s page references the managed bean, the managed bean creates a separate instance of this object and adds it to the pageFlow scope of its task flow.
Choose this scope if you want the managed bean to be accessible across the
activities within a task flow. A managed bean that has a pageFlow scope shares
state with pages from the task flow that access it. A managed bean that has a
pageFlow scope exists for the life span of the task flow.
If another task flow’s page references the managed bean, the managed bean
creates a separate instance of this object and adds it to the pageFlow scope of its
task flow.

backingBean: A backing bean is a convention to describe a managed bean that stores accessors for UI components and event handling code on a JSF page. It exists for the duration of a request and should not be used to maintain state.Use this scope if it is possible that your task flow appears in two ADF regions on the same JSF page and you want to isolate each instance of ADF region.
A backing bean is a convention to describe a managed bean that stores accessors for UI components and event handling code on a JSF page. It exists for the duration of a request and should not be used to maintain state.Use this scope if it is possible that your task flow appears in two ADF regions
on the same JSF page and you want to isolate each instance of ADF region.

view :Use this scope for managed bean objects that are needed only within the current view activity and not across view activities. It defines scope for each view port that ADF Controller manages, for example, a root browser window or an ADF region.The life span of this scope begins and ends when the current viewId of a viewport changes. If you specify view, the application retains managed bean objects used on a page as long as the user continues to interact with the page. These objects are automatically released when the user leaves the page.

Request : Use request scope when the managed bean does not need to persist longer than the current request.

Get value from selectOneChoice in Oracle ADF

public void selectOneChoice1_valueChangeListener(ValueChangeEvent valueChangeEvent) {
//for iterator name click binding tab in the jsf page
DCIteratorBinding listIter = getBindingsForDCB().findIteratorBinding(“yourViewObj1Iterator”);
int curIndex = (Integer)valueChangeEvent.getNewValue();
Row datRow = listIter.getRowAtRangeIndex(curIndex);
String name = (String)datRow.getAttribute(“Code”); //as in data control
}