How to refresh an OA Framework page using Java Script?

Hey there, today we are going to look at some javascript implementation in OA Framework and as the title of the post suggests we will see that how can we refresh an OA Framework page using javascript.

Assumptions:
1. You already have an OA Framework page (XXTrialPG).
2. You have a controller (XXTrialCO) attached to XXTrialPG.
3. You want the OA Framework page to refresh in every 20 seconds.
4. You have imported all the required regions and/or items in XXTrialCO.

Let’s take this in steps for easy remembrance.

Step1. Create a handle for OABodyBean
OABodyBean bodyBean = (OABodyBean) pagecontext.getRootWebBean();

Step2. Create a variable of String type and assign the below mentioned javascript code to the string variable.
String javaS = “javascript:setTimeout(‘window.location.reload()’,20000)”;

Note: Here 20000 means 20 seconds mentioned in milliseconds

Step3. Set the String variable on the onLoad() method of OABody bean, this will ensure that when the OA Framework page is rendered, the corresponding javascript code is triggered
bodyBean.setOnLoad(javaS);

That’s it Folks.
Thanks for reading.
Till the next post
Take Care

Tagged , , . Bookmark the permalink.
  • badri

    where we write this code

    • techhoney

      Hi Badri,

      Write this code in Page Controller.

      Thanks.

      • badri

        i wrote this code in PR.bt its not working

        • techhoney

          Are you getting any error?

          • badri

            i m nt getting any error.bt page is not refreshing

          • techhoney

            Try this,

            String onLoadFunction = “n function onLoadFunction (refTime){ ” +
            “n setTimeout(“location.reload(true);”,refTime);” +
            “n } ” ;
            pageContext.putJavaScriptFunction(“onLoadFunction”,onLoadFunction);

            OABodyBean BodyBean = (OABodyBean) pageContext.getRootWebBean();
            BodyBean.setOnLoad(“JavaScript:onLoadFunction(5000)”);

            ====
            5000 means 5 seconds

          • techhoney

            As you said that the values are stored in data base as 10th, 23rd and so on.

            Let’s take an example of 23rd as value..

            Since all the values has at least ‘th’, ‘nd’ or ‘st’ etc attached to them, you can use the sql substring function to strip last 2 alphabets from the value. If 23rd is a value from database then using substring get the last 2 alphabets i.e. rd and then using the rawtextbean (as you are doing currently) you can superscript the stripped text.

            Use the link to know substring method
            http://www.techhoney.com/oracle/function/substr-function-in-oracle-sql-plsql/

            another approach which you can use is to use the substring java method to get the last 2 alphabets..

          • badri

            Hi
            i created one lov in custom page.

            lov item name States-

            values are : AP,TG,TN,MP,UP,ect…

            if i enter a correct value(i.e AP) in lov item no need to open lov popup.it will move to next item bt it opens lov popup.

            please give some advise.

          • techhoney

            Hi Badri,

            Are you working in 11i or r12?

            Thanks

      • badri

        i wrote this code in PR .bt it is not working