Showing posts from 2013

OAF : Trace OAF Pages

To enable diagnostic for specific user set Profile Option FND: Diagnostics to YES
See this article about profile option

Now login at application, you will find in global buttons "Diagnostics" link, click it.
Enter the follwing
Diagnostic: Show Log on Screen
Log Level : Statement (1)
Module : %

Now Click go button

Now when opening any page at application you will find trace at button of page.


OAF : Programatically Add Region to OA Page

Sometimes in OAF, you want to add a region to OA Page.

For example i had a requirement to add employee summary region to another page.
Employee Summary Page exists at MDS at this path "/oracle/apps/per/selfservice/common/webui/AsgSummaryRN".

Application module that is used with this region is "oracle.apps.per.selfservice.common.server.SummaryAM"

I wrote the following code to add this page to another page at controller of OA page

ipublic void processRequest(OAPageContext pageContext, OAWebBean webBean) { super.processRequest(pageContext, webBean); OATableLayoutBean empSummaryBeean = (OATableLayoutBean)this.createWebBean(pageContext, "/oracle/apps/per/selfservice/common/webui/AsgSummaryRN", "AsgSummaryRN", true); empSummaryBeean.setApplicationModuleDefinitionName("oracle.apps.per.selfservice.common.server.SummaryAM"); empSummaryBeean.setStandalone(true); webBean.addIndexedChild(0, empSummaryBeean); }…

OAF : Configure Jdeveloper for OAF

Developers use specific version of Jdeveloper to extend or customize OAF pages.
Each Oracle OAF framework has specific version of Jdeveloper used with it.

Before configuring jdeveloper you must know current OAF version used by Oracle EBS.
To get OAF version used by your instance, login at application and click "About this page" link on the left button of OA page and select "Technology Components" tab.

After knowing your OAF framework version , login at Oracle Support and open Note ID: ID 787209.1 - How to find the correct version of JDeveloper to use with eBusiness Suite 11i or Release 12.

Download correct Jdeveloper patch and extract anywhere at your machine.

Follow the following steps to configure Jdeveloper

1- Specify Path of jdeveloper
Right click on My Computer, select Properties, click System Properties, Select Advanced tab , Click Environment Variables as given below screen shot
Variable name : JDEV_USER_HOME

Variable value : <>

2- Download DBC file

OAF : Disable Global Buttons in Page

I write snippet code to disable global buttons in OAF page.
You can add the following code to Controller class of the page that you want to disable global buttons inside it.

public void processRequest(OAPageContext pageContext, OAWebBean webBean) { super.processRequest(pageContext, webBean); OAPageLayoutBean pageLayoutBean = (OAPageLayoutBean)pageContext.getPageLayoutBean(); pageLayoutBean.prepareForRendering(pageContext); OAGlobalButtonBarBean globalButtonsBean = (OAGlobalButtonBarBean)pageLayoutBean.getGlobalButtons(); globalButtonsBean.setRendered(false); }

Route HTTP to HTTPS in HttpClient

I published before an article about JAVA : Get html Page Source through Website URL that HttpClient was used to send Get method and get Response.

Sometime developer want to route Http to Https when invoking Urls.
So You can use WebClientWrapper.wrapClient to do this issue.



import org.apache.http.client.HttpClient;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;

public class WebClientWrapper {
    public static HttpClient wrapClient(HttpClient base) {
        try {
            SSLContext ctx = SSLContext.getInstance("TLS");
            X509TrustManager tm = new X509TrustManager() {


JAVA : Get html Page Source through Website URL

To get source code of website page you can use HttpClient ,I will  send GET method and then get response.
The response has content of website URL.

I used Apache HttpClient package to implement this task.

In this Class I used  getStringFromInputStream method that was I was posted before in Convert InputStream to String.

here you can find Class do this task
Note I use static method WebClientDevWrapper.wrapClient, you can find its code in the article Route HTTP to HTTPS in HttpClient

import; import; import; import; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.DefaultHttpClient; public class WebsiteSource { public static String getSource(String url) throws Exception { String retValue = ""; HttpClient httpclient = new Defa…

JAVA : Convert InputStream to String

You can use the following snippet to convert InputStream to String

private static String getStringFromInputStream(InputStream is) { BufferedReader br = null; StringBuilder sb = new StringBuilder(); String line; try { br = new BufferedReader(new InputStreamReader(is)); while ((line = br.readLine()) != null) { sb.append(line); } } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } return sb.toString(); }

OAF Overview

This post will explains some terminologies that is used in Oracle Application Framework (OAF).

Entity Object - business component entity objects maps to database table or view that allow DML operations and that used to cache data result set and perform validation before post changes to database. 

Association Object - business component association objects implement the relationships between different entity objects and can mapped to database referential integrity constraint or non existing referential integrity constraint and this case constrain will be validated in OAF but not in database.

View Object - business component view objects are used to display data in UI pages and it can be based on
1- Entity Object or many entity objects and this case it supports DML operations.
2- SQL queries  : that's doesn't support DML operations
3- Static : Programmer create structure of view object attributes and can add static data also.
4- Programmatic : Programmer write code at ru…

ADF : Working with ViewCriteria

View Criteria's are additional where clause added at runtime to base View Object Query.

 Programmer can create view criteria declaratively or programatically.

1. Create View Criteria DeclarativelyOpen View Object in Edit and in "Query" tab you can click "+" add pencil to create new view criteria

2. Control View Criteria Programatically.

a- Get View Criteria from View Criteria manager within View Object and then apply it
ViewCriteria applyVC = myViewObject.getViewCriteria("MyViewCriteriaName");
b- Applying Multiple view Criteria's

When multiple view criteria's are applied to the view object, the view criterias gets appended or replaced depending upon the way you use applyViewCriteria API
Replacing Existing view criteria's :

myViewObject.applyViewCriteria(applyVC) or
will erase all previously applied view criterias and apply the cur…

Random Numbers in Java

Previously I posted  about Generate Random Passwords in Oracle that was using PLSQL.
Today I will post about java randoms.

Java provides two classes to generate random numbers: Random and SecureRandom.
Random is faster than SecureRandom, but it uses a 48 bits seeds which is not enough for the long type.
Moreover, it is not 'random enough' for cryptography. SecureRandom, is slower than Random, but can be used for cryptography.

The following code example shows how to generate a random number within a range for int, long, float and double.

Note rangeStart , rangeEnd is range period of generated numbers .

int rangeStart = 50; int rangeEnd = 100; SecureRandom secRandom = new SecureRandom(); int inclusive = rangeEnd - rangeStart + 1; int exclusive = rangeEnd - rangeStart; int randomIntInclusive = secRandom.nextInt(inclusive) + rangeStart; int randomIntExclusive = secRandom.nextInt(exclusive) + rangeStart; System.out.…

Close Resources in Java

In java when using any resources like Files, Streams, Database Connection and DataSets etc .... , you must close resources at end of processing at your code.

For Example : Streams 

File f = new File("myFile.txt"); FileOutputStream fos = null; try { fos = new FileOutputStream(f); // Do something... } catch (FileNotFoundException ex) { // Display error message } finally { // Closing resource if (fos != null) { try { fos.close(); } catch (IOException ex) { //Here , Hide Exception } } }
All previous code in Blue color are used to close resources.
So to save time and make code more readability you can use IOUtils Appache packages  to close resources quietly
finally{ IOUtils.closeQuietly(fos); }

For Example : Database Statement

finally{ DBTransaction txn = this.…

Run JavaScript from Native Java

I wrote in previous post Execute Javascript code from Java Code how to execute java script in Oracle ADF.
But in this post I will explain how to call Javascript from native Java.

The following code snippets will illustrate how to evaluate Javascript code and invoke functions and get return value.

import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class CallJavaScript { public static void callJsCode(String jsCode) throws ScriptException, NoSuchMethodException { // Retrieving the Javascript engine ScriptEngine se = new ScriptEngineManager().getEngineByName("javascript"); try { se.eval(jsCode); } catch (ScriptException e) { e.printStackTrace(); } try { Invocable jsinvoke = (Invocable)se; System.out.println("…

Iterate Through Java Map

There are multiple ways to iterate through a Java Map.

Assuming the following map declaration:
Map mapObj = new HashMap();

//Use Iterator [Generic]
Iterator> iter= mapObj.entrySet().iterator();
while ( iter.hasNext() ) {
    Entry item =;
    System.out.println(item.getKey() + " - " + item.getValue());

//User Iterator [Without Generic]
Iterator iter= mapObj.entrySet().iterator();
while ( iterator2.hasNext() ) {
    Entry item = (Entry);
    System.out.println(item.getKey() + " - " + item.getValue());

// Use For Each [Generic]
for ( Entry item : mapObj.entrySet() ) {
    System.out.println(item.getKey()+ " - " + item.getValue());

// Use For Each [Without Generic]
for ( Entry item : mapObj.entrySet() ) {
    System.out.println(item.getKey()+ " - " + item.getValue());

//Fetch Value using Key
for ( String key : mapObj.keySet() ) {
    System.out.println(key + " - " + mapObj.get(key));

// Loop through Keys only
for ( Stri…

ADF : Change View Criteria Columns at Runtime

When creating view criteria related to view object, then all querable attributes are displayed in view criteria by default.
So I want to change the properties of this attributes at run time pragmatically to display or hide specific attributes in view criteria.

I developed the following method for this purpose, You can add this method to ViewObjectImpl class.

I pass attribute name and a Boolean value to determine display in view criteria or no.

public void setQuerable(String attributeName, Boolean isQuerable) { int indx = this.getAttributeIndexOf(attributeName); ViewAttributeDefImpl attr = (ViewAttributeDefImpl)this.getAttributeDef(indx); attr.setQueriable(isQuerable); }


Uncommitted data warning

If you are working entry data page and some feilds has been changed and you moved to another page, data still in cache but not posted or commited.
So to show warning of unsaved data before moving to another page you can do this by setting "Uncommitted data warning" property of af:document to "true". Then whenever user change data and  move out of current page or close the browser, it will display a warning of unsaved data


Set Sequence Number by Groovy Expression

Before I posted how to set Sequence Number using Code Get Sequence Next Value in ADF

Today I will illustrate how to set sequence number using groovy language.
You can do it by setting default value expression at primary key 

(new oracle.jbo.server.SequenceImpl("My_seq_name",adf.object.getDBTransaction())).getSequenceNumber()


OAF : Bounce Appache Server

Connect to server using putty and execute the following commands

1- Enter commands folder

2- execute the following commands to stop Apache stop stop

3- Execute the following commands to start Apache start start


Compare JBO Date Programatically

To compare two jbo date programatically, l convert jbo date to sql date and then compare sql dates

oracle.jbo.domain.Date jboDate1 = new oracle.jbo.domain.Date(); oracle.jbo.domain.Date jboDate2 = new oracle.jbo.domain.Date(); java.sql.Date sqlDate1 =jboDate1.dateValue(); java.sql.Date sqlDate2 =jboDate2.dateValue(); //Compare sql Date if (sqlDate1.before(sqlDate2 )) {      //Write Your Code }

Get All PLSQL Errors

I developed a function to get all PLSQL errors in schema.
This function should be used after calling program units so that can get PLSQL errors and you can use for logging and tracing.

Function Code


OAF : Get Current Row in Table

Sometimes you want to get current row in table. To apply this you can use the following code in controller and write it inside processFormRequest method.

    public void processFormRequest(OAPageContext pageContext,                                    OAWebBean webBean) {         super.processFormRequest(pageContext, webBean);         //Get application Module         OAApplicationModule am = pageContext.getApplicationModule(webBean);                 //Get Row Refrence         String rowReference =             pageContext.getParameter(EVENT_SOURCE_ROW_REFERENCE);                     //Get current Row using Row Reference            OARow currRow = (OARow)am.findRowByRef(rowReference);                 //Get attribute value from current row         String attrValue = (String)currRow.getAttribute("AttrName");     }


Oracle OAF MDS Repository

MDS repository stores all pages and regions used in OAF pages and contain personalization and extensions.

All MDS data stores in the following 4 tables.
1. JDR_PATHS: Stores the path of the documents, OA Framework pages and their parent child relationship.
2. JDR_COMPONENTS: Stores components on documents and OA Framework pages.
3. JDR_ATTRIBUTES: Stores attributes of components on documents and OA Framework pages.
4. JDR_ATTRIBUTES_TRANS: Stores translated attribute values of document components or OA framework pages.

JDR_UTILS PL/SQL package supports the MDS repository and can be used to query and maintain the repository.


Start Weblogic without user and password

When you want to launch your weblogic server at production, you need to use the in your bin folder.

But each time it's launched it's asking you to authenticate yourself by typing a user and password. It's a problem when you want to automate the execution of your server...

To avoid this problem all you need to do is creating a file named "" and insert into the two following lines :

password=<yourPassword> this file must be placed in each server security folder : $WLS_HOME/user_projects/domains/<domainName/servers/<serverName>/security
Then, start server, it shouldn't ask you for anythin, then reopen your file, password and username should be automatically encrypted ! Thanks

Avoid java out of memory with Weblogic

This is common exception always exists if you install weblogic and doesn't extend memory arguments in server.

The file "" in $WLS_HOME/user_projects/domains/<domainName>/bin/ has configuration of domain.

If you edit this file it will have the following default values.
MEM_ARGS="-Xms256m -Xmx512m" export MEM_ARGS MEM_PERM_SIZE="-XX:PermSize=48m" export MEM_PERM_SIZE MEM_MAX_PERM_SIZE="-XX:MaxPermSize=128m" export MEM_MAX_PERM_SIZE
you should modify the MEM_ARGS java memory value depending of your server, here is the suggested to increase. MEM_ARGS="-Xms2024m -Xmx3036m" export MEM_ARGS MEM_PERM_SIZE="-XX:PermSize=128m" export MEM_PERM_SIZE MEM_MAX_PERM_SIZE="-XX:MaxPermSize=512m" export MEM_MAX_PERM_SIZE

Note : choosing the values depend on you server hardware.


Oracle OAF Profile Option

Oracle OAF has some important profile options which is useful in extension or personalization.
I will list it below and write breif about every profile option.

1- FND_Diagnostics
Setting this profile option to YES, will add anew link "Diagnostics" at top right on page, that allow developer to trace logs.

To add log when coding use the following code in Controller or Application Module
In Controller write this code:-
pageContext.writeDiagnostics(this, "Phrase will be added to logs", 1);

In Application Module write this code
getOADBTransaction().writeDiagnostics(this, "Phrase will be added to logs", 1);

2- Personalize Self-Service Defn
 Set this profile to Yes to allow personalization. 

3- FND: Personalization Region Link Enabled :
Set this profile to  Yes  show "Personalize  Region" links above each  region in a page.

4- Disable Self-Service Personalization
Yes will disable all personalization at any level.

5- FND: Personalization Document Root Pa…

Redirect to ParentAction Programatically

In your task flow you can redirect parent action programatically using the following method.

public void redirectToParentAction(String parentAction) {         ControllerContext ctrlCtx = ControllerContext.getInstance();         ViewPortContextImpl portImpl = (ViewPortContextImpl)ctrlCtx.getCurrentViewPort();         ParentActionEvent parentEvent = new ParentActionEvent(parentAction, true);         portImpl.queueParentActionEvent(parentEvent);     }


Generate View URL in ADF

The following  getUrl method generates URL for you view in ADF application.
You pass servlet name and view id, I also overloaded getUrl method for making default servlet name as "faces".

public static FacesContext getFacesContext() { return FacesContext.getCurrentInstance(); } public static ExternalContext getExternalContext() { return getFacesContext().getExternalContext(); } public static String getURL(String servletName, String viewId) { HttpServletRequest request = (HttpServletRequest)getExternalContext().getRequest(); String requestUrl = request.getRequestURL().toString(); StringBuilder newUrl = new StringBuilder(); newUrl.append(requestUrl.substring(0, requestUrl.lastIndexOf(servletName))); newUrl.append(servletName); newUrl.append(viewId.startsWith("/") ? viewId : "/" + viewId); return newUrl.toString(); } public st…

Hijrah Date in Oracle Database

Some Arabic countries use Hijrah calendar specially in Saudi Arabia.
So today I will post about Hijrah Date and how to convert between different calendars.

The main notes in this post
1-NLS Calendars in Oracle Database
2-Convert Georgian calendar to Hijrah calendar
3-Convert Hijrah Calendar to Georgian
4-Fix deviations between calendars
5-How to create lexical file for the deviation

Get Oracle Home & Oracle SID from PLSQL

The below script gets Oracle Home and Oracle SID from PL/SQL