Tuesday 6 September 2011

How to Use JAVA Script in OAF Page

Call this method from Process Request Or Process Form Request based on the requirement

protected void changeLinkColor(OAPageContext pageContext, OAWebBean webBean)
      {
        //Create Java script function to hide Select All and Select None links
        StringBuffer scriptFunction = new StringBuffer(400);
        scriptFunction.append("function changeLinkColor(){");
        scriptFunction.append("  var arrElements = document.getElementsByTagName(\"a\");");
        scriptFunction.append("  for (var i=0; i<arrElements.length; i++) {");
        scriptFunction.append("      var element=arrElements[i];");
        scriptFunction.append("    if(element.id.indexOf(\"ManagerName\") != -1)");
        scriptFunction.append("      element.style.color = '#ed1c24'; ");
        scriptFunction.append("    }");
        scriptFunction.append("  }");

        //put the java script function in pagecontext
        pageContext.putJavaScriptFunction("changeTableLinksColorToRed", scriptFunction.toString());

        OAWebBean body = pageContext.getRootWebBean();
        if (body instanceof OABodyBean)
          ((OABodyBean)body).setOnLoad("changeLinkColor();"); //call the javascript function when the page loads
      }

1 comment:

  1. Hi Santhosh
    I am new to OAf and Javascript
    In my OAF page i need to implement autotab feature for a table i.e whenever user entered value reaches maximum length of that field the cursor should go to next editable column of the same row. Could you give any suggestion on how to implement this?

    ReplyDelete