Thursday, 3 February 2011

Creating ADF Poll

Creating ADF poll is one of the easiest thing in ADF.
Here you have to just mention the poll interval just and it will call the poll in that interval continuously.

To create ADF Poll (af:poll) just create one Fusion Web Application and Create one Fusion Web Project. 

In that project create one managed bean to create the poll listener method.
For me it is CallPollBean.java.



Now create one Poll Listener method,

For me it is :

    public void callPoll(PollEvent pollEvent) {
        // Add event code here...
        System.out.println("Poll Called");
        DateFormat formatter = new SimpleDateFormat("dd/MM/yy HH:mm:SS");
        System.out.println(formatter.format(new Date()));
    }


Now create one JSF page. 

Create af:poll component in the page. 

For me the component is like below:

 <af:poll id="p1" interval="60000" pollListener="#{callPoll.callPoll}" 
                     immediate="true" rendered="true"/>

Now if you run the page you will see that the callPoll method is being called at an interval of 1 minute.

The interval is in milli second format.

In 11.1.1.4 (JDev 11g PS3) release there is one extra property timeout which is set to default 10minutes (timeout="600000 "),


you can change the timeout as per needed for infinite poll use timeout="-1"




Stop Execution Of View Object at First Load of Page

This can be done in many ways.

I am going through one simple way without creating managed bean or using task flow.

First Create the Fusion Web Application.
Then create the ADF Business Components to create Entity Object, View Object and Application Module in  Model project



Now create the page to show the table data. 


Now if you run the page you will see that the VO is executed on First Page Load and it is showing data in table.

To stop that first create the <VOName>ViewObjectImpl class for me it is EmployeesViewObjectImpl.java

in this class override the method


    protected void executeQueryForCollection(Object object, Object[] object2, int i)


use the below code to override.


       @Override
    protected void executeQueryForCollection(Object object, Object[] object2,
                                             int i) {

        if (counter > 0) {
            super.executeQueryForCollection(object, object2, i);
        } else {
            counter = counter + 1;

        }
    }








Now if you run the page you will not be able to see the data. On Execute Button Click the data can be shown.







For further queries you can add comment on this blog.



Tuesday, 1 February 2011

Favicon Icon In ADF

To create Favicon Icon for Your ADF application without changing context root, you can follow the following steps.

Place the favicon.ico in your Webcontent root.

For me it is like FaviconViewController\public_html

Refresh Your ViewController project it will show favicon.ico in WebContent section as shown in picture.


Now create one jspx page that will use the favicon.ico



Right Click the af:document in structure window and enable the metaContainer facet as shown in the picture.



Inside metaContainer facet create one af:outputText as shown in picture.







Put the value of the outputText
as
<link rel='SHORTCUT ICON' href='#{facesContext.externalContext.requestContextPath}/favicon.ico'/>




set the escape property of the outputText to false.



Now run your page you will be able to see the favicon in supported browsers.



Please comment in comment section for any queries or suggestion.


Favicon can be added in other ways also..

Showing Data Based on List Of Values And Bind Variables

 Create one Fusion Web Application with Model and View Controller projects.

Create ADF Businesss Components.

Like below I have created,

One HRApplication is created with HRModel and HRViewController projects.

Then created the entities(Employees, Departments) from Employees and Departments tables.



Then created the updatable view objects.(EmployeesViewObject,DepartmentsViewObject).



Then created the Application Module (HRAppModule)


Now click finish to complete the Business components.

Now I should create the view criteria to create the criteria and create the bind variable to pass the selected data from list of values.

First Create the List Of Values to be displayed in criteria.

I am creating it to show employees present in one department.

To do that

First open the EmployeesViewObject.xml in "Overview" mode.

Go to the Attributes page.

Only Employees entity's attributes are being shown there.

To display the Departments entity's attribute . Go to "Entity Objects" option. Add the Departments entity object on right side.


Now come to "Attributes" section again.

Right click the down arrow beside the green add button as shown in the picture.

Choose option Add Attribute From Entity



Chhose all the Deaprtments' Attributes.

Now Select the DepartmentName attribute.

Click the Green Add Button related to List Of Values:DepartmentName as shown in picture.



Choose the List Of Values properties.



Now go to "Query" portion to create the view criteria.



Now your business components are ready



Now Go to HRViewController project.

Create one jspx page from JSF> JSF Page


Now refresh the Data Control Pane.



Drag the EmployeesViewObjectCriteria in page's center region.

Choose Query> ADF Query Panel With Table

Now create the table with suitable attributes.

You will be able to see the page with LOV.
 The value selected in LOV is being passed to the Bind Variable created.




In this way List Of Values with input text can also be created.



 

Friday, 21 January 2011

Application Module - Optimistic Lock vs Pessimistic Lock

In Application Module the locking is by default pessimistic lock.

jbo.locking.mode is pessimistic by default.

But the practice should be optimistic locking.

How to change the locking mode.

We can easily change the locking mode by opening
"EDIT BUSINESS COMPONENT CONFIGURATION".



change the value to optimistic.

The pessimistic locking holds lock on database but optimistic does not hold lock on database.

So in case concurrent update

1> pessimistic locking - The second user for concurrent data update will stuck with error until first user saves or undo data change.
The second user will be forced to wait until first user will Save or Undo his changes in order to proceed with data commit. Another option for the second user - Undo his change in the current row and proceed with other rows editing. When the first user will close his transaction, the second one will be able to save his changes for previously locked record as well.

2> optimistic locking - The first user will not hold database lock and second user will be able to continue his work. At the same time, first user will be able to press Save button second time, and his data will be committed.

So for general optimistic locking is better to use.

By the way

There are three types of locking:
1. normal
2.optimistic
3.pessimistic



 

Thursday, 20 January 2011

Handling Stale Data

While using ADF one internal feature of ADF model is Data Caching. So for neseted application modules sometimes it makes problems like RowInconsistentException.

To remove that we can use setClearCacheOnCommit.
By default its value is false.

But if we make it true it will clear the previous cache on every commit. So the data updated by other users always get updated.

It can be done by two ways.

1. Open the ApplicationModule.xml in source mode. and set the ClearCacheOnCommit="true"


or
2. If AppModuleImpl.java is created use the following code there.

 this.getDBTransaction().setClearCacheOnCommit(true); in constructor.

This should solve the problems like Stale Data.

Use Server's Data Source In AM Instead Of Application Connection DataSource

Using Data Source instead of normal JDBC connection has lot of advantages. Major one is Data Source behaves dynamically. One can change the Data Source's Configurations also. While the deployed application will not be affected if Data Base Objects do not get altered.

But one problem I have found in industry is that how to configure different data sources in application module(Root Application Module) .

Normally for testing purpose we do not use Data Sources we use application modules jdbc connection.

To configure data sources we can choose two types of Data Sources(Based on Authentication)

1. Application
2. Container

As we are discussing here about using server's Data Source I will be going with Container based one.

To configure this I suppose I will be using "HRDataSource" as Data Source Name.

First I shall edit the Application Module Configuration to refer HRDataSource.

To do that I should follow these steps:

1. Right Click On AppliationModule.xml(MSService.xml in picture).
2. Click Configurations - It will open Manage Configurations wizard.
3. Now click on edit - and edit the DataSource as java:comp/env/jdbc/DataSourceName

Click save all


Now we have added the DataSource in AM. But if we deploy the application in server we may still get errors though jdbc/HRDataSource exists in server.

We have to configure the authentication to be of Container.

To do that we should edit the web.xml of View Controller project.

We should one Data Source Reference there of Authentication Container.

The configuration should be like below image. Data Source is of javax.sql.DataSource type.



Now if we deploy the application it should take HRDataSource for Data Base connection.

So If you need to modify the DataSource name , just modify bc4j.xcfg located in common folder and web.xml located within WEB-INF folder.

Here the Data Source is found out using context lookup.

as like below.

Context envCtx = (Context) initCtx.lookup("java:comp/env");

// Look up our data source
DataSource ds = (DataSource)envCtx.lookup("jdbc/HRDataSource");

// Allocate and use a connection from the pool
Connection conn = ds.getConnection();
... use this connection to access the database ...
conn.close();


-------------------------------------------------------------------------------------------------------

The Data Source can be configured by directly and only in bc4j.xcfg file only. Without mentioning any reference in web.xml

just put the jndi name of the Servers Data Source in 'Custom JDBCDataSource="jdbc/HRDataSource" />' in bc4j.xcfg file deploy it in server.

It will run as expected.


--------------------------------------------------------------------------------------------------------