Wednesday, December 30, 2015

Apply Dynamic JDBC in ADF Application (Step-by-Step)

In some situations the business require that ADF application can connect to different database users depending on the login user. For example if user1 login, the ADF application will connect to database user hr/hr. If user2 login, the ADF application will connect to database user hr2/hr2.
This is call Dynamic JDBC.

In this url you can see how to apply this dynamic JDBC, but in my post I will simplify this url by creating a sample ADF application and go step by step for how to apply dynamic JDBC to this ADF application.

I use JDeveloper 11.1.2.4.0.

Note: From Step1 to Step5 it just steps for creating a simple ADF application. Applying the Dynamic JDBC to this simple application is starting from Step6.

Step1:
Create a simple ADF Application connect to "hr" database, this application will contains only 1 ViewObject (Employees) and will contains 2 jspx pages (login.jspx and emp.jspx)



Step2:
From faces-config.xml --> Navigation Rules define outcome to the two jspx pages.
login.jspx---> login
emp.jspx----> emp


Step3:
- In the login.jspx page add two inputTexts (Username and Password) and one command button for login.
- Bind Username inputText and Password inputText to the back bean.
- Create action for the login command button to read the username and password then navigate to emp.jspx page.



Step4:
In the emp.jspx drag EmployeesView1 to the page and add logout link to the page 



The back bean should be:


Step5:
Run login.jspx page.

Now we have created a simple ADF application and we will now apply dynamic jdbc to this application.

Step6:
Open AppModule and set "Connection Type" to JDBC URL for both AppModuleShared and AppModuleLocal



Step7:
In the login button action we will store username/password it in session.
The login button action will be:



Step8:
Create new Filter (DynamicJDBCBindingFilter.java) extends ADFBindingFilter.



Step9:
Create Class (DynamicJDBCEnvInfoProvider) as



Step10:
Create Class (DynamicJDBCHttpSessionCookieImpl) as



Step11: 
Create Class (DynamicJDBCSessionCookieFactory) as



Step12:
In web.xml update adfBindings and make it point to DynamicJDBCBindingFilter



then add filter mapping to adfBindings filter




Step13:
In AppModule update jbo.ampool.sessioncookiefactoryclass in AppModuleLocal and AppModuleShare to point to DynamicJDBCSessionCookieFactory




Step14:

Now run login.jspx and login with database username/password = hr/hr you will successfully login and  get the data



Logout then login again with wrong password as hr/hr1 you will get "Invalid username/password".





You can download the sample application from here




Tuesday, December 29, 2015

Get JDeveloper and ADF Icons and Styles

Some developers want to get some icons which used in ADF components or JDeveloper. Examples of these icons (edit icon, LOV icon, undo icon,...) or get some css files which used for styling.

You can find these icons and css files on the jar file adf-richclient-impl-11.jar

You can find this jar in the path like:

C:\Oracle\Middleware\oracle_common\modules\oracle.adf.view_11.1.1\adf-richclient-impl-11.jar




You can extract this jar file then open "adf" folder and you will find 2 folders:

1-  "images" this folder will store icons.
2- "styles" this folder will store css files.






Friday, December 11, 2015

ADF Table Filter Case Insensitive and Search by Contains Instead of Start With

In ADF table if you enable column filter this filter by default will search by "start with" and it will be case sensitive . For example in table employees if you have employee name = Hermann and you try to search by "man", the search will return no result


but if you search by "Herm" it will return result


If you try to search by "herm" it will return no result.



This is because the filter by default is case sensitive and will search by start with.

In many cases we need the all tables filters be case insensitive and search by contains not start with. You can search by case insensitive by setting filterFeatures="caseInsensitive" for  each af:column but you need to do this in all af:column in your application and it will not be a proper solution.

You can search with contains by typing your string between '%', but we need something to be more easy than typing %.

To make the the ADF table filter be case insensitive and search by contains follow these steps:

1- In model project create new class "CustomViewImpl" this class should extend oracle.jbo.server.ViewObjectImpl


2- In this class override getCriteriaItemClause(ViewCriteriaItem viewCriteriaItem) and write this code:





3- Go to Model --> Project Properties --> ADF Business Components --> Base Classes --> View Object --> change Object to point to your CustomViewImpl class


4- Open ViewObject --> Java --> Java Classes --> Generate View Object Class



5- If you open the generated ViewImpl class you will find it extend the CustomViewImpl class


6- Run the application and test.

You can download the sample application from here

(This sample developed in JDev 11.1.2.4.0)