Tuesday, September 25, 2007

Implementing a simple watch in a OA Framework Page

I hope this is interesting ... implementing a watch in OA Framework page.There can be several other functionalities, one can do after implementing this watch.Here i am just writing a simple function for javascript watch,you can take an idea.... and change this function accordingly.

Just read this function.....

/* Here is the javascript function, which is self explainatory
Read this function carefully
to understand it.*/

function update()
{
//Define a new date object
var today=new Date();

var hours=today.getHours();
var minutes=today.getMinutes();
var seconds=today.getSeconds();

//for formatting output
if (hours<10)
hours="0"+hours;
if (minutes<10)
minutes="0"+minutes;
if (seconds<10)
seconds="0"+seconds;

//writing output to message text input
document.getElementByID('OAclockDisplay').value=hours+":"+minutes+":"+seconds;

//refreshing ever sec
setTimeout("update()",1000);
}

I hope this clear. Now here are the steps how you can put it in your OA Framework page.Add a message text input to your page, say its id is "OAclockDisplay".

Now add this code in process request of controller of page:

//storing javascript function is a string
// "\" is used as escape character
String s="function update(){var today=new Date();var hours=today.getHours();var minutes=today.getMinutes();var seconds=today.getSeconds();if(hours<10){hours=\"0\"+hours;} if(minutes<10){minutes=\"0\"+minutes;} if(seconds<10){seconds=\"0\"+seconds;} document.getElementById('OAclockDisplay').value=hours+\":\"+minutes+\":\"+seconds;setTimeout(\"update()\",1000);}";

//getting body bean
OABodyBean bodyBean = (OABodyBean)pageContext.getRootWebBean();

//attaching javascript function to page
pageContext.putJavaScriptFunction("update",s);

// calling this function on load of body bean
String javaS = "javascript:update();";
bodyBean.setOnLoad(javaS);

We are done, run this page you will be able to see a watch in oa framework page in that particular message text input.
Cheers!

12 comments:

sekhar said...

Thanks Mukul,Good Article

Mukul Gupta said...

Thanks for the comments, dude.

Sourav said...

Hi,
mukul its great clock,
but iwant to know can we implement it as a Read only MessageTextInput or MessageStyledText or Header

Sourav said...

Hi,
mukul its great clock,
but iwant to know can we implement it as a Read only MessageTextInput or MessageStyledText or Header

Mukul Gupta said...

sourabha ,
For that u need to use raw text bean with same js function, an u can use document.write() to write time in ur recursive function that i have given.

--Mukul

Gravity said...

That was pretty cool.
Thanks

Unknown said...

Thanks Mukul,
This is a very helpful article for me.......thanks once again

Unknown said...
This comment has been removed by the author.
Krishna said...

Hi mukul,
could you please tell me how to call a Oracle function from OAF..I am pretty new to OAF

Thanks & Regards
krishna

Mukul Gupta said...

Thanks Kimberly, will continue to write more informative articles on my blog.
--Mukul

Dipak Oracle Apps Technical Consultant said...

Thanks mukul,
u have done great job but i didnt get where to write the javascript code in oaf
plz help

Pradeep said...

Hai Mukul,
Related to message Choice I am working one requirement.Need to
get the value from one messageChoice and pass to another messageChoice.Whether its possible?