5 Replies Latest reply: Feb 14, 2013 2:01 AM by Frank Nimphius-Oracle RSS

    Call Javascript function on ADF

    esonerdene
      Hi All Experts,

      I am having a problem working with javascript on adf.
      Actually I have javascript function called makeHighLight() and too many input text fields are there.
      And i want to call javascript function as i mentioned above.
      I can call js function using a clientListener on my input text field. But I have too many fields.
      I don't want to set client listener on each of my text fields. Is there any way to do this.

      Please help!
        • 1. Re: Call Javascript function on ADF
          Frank Nimphius-Oracle
          Hi,


          depends on how you want your JS function to be triggered. If the function is triggered by a valueChange event (or another event related to an input text field) then you will have to add the clientListener component to all of the input text fields. If the function is triggered e.g by a command button then you can lookup the input text component starting from the ADfPage.PAGE root object using fincComponentByAbsoluteId()

          Frank
          • 2. Re: Call Javascript function on ADF
            Puthanampatti
            you can try something like this...jquery...

            for (String focusField : focusFieldsList)
            {
            StringBuilder script = new StringBuilder();
            script.append("var textInput = ");
            script.append("AdfPage.PAGE.findComponentByAbsoluteId($('[id$=it1]').attr('id'));");
            script.append("if(textInput != null){");
            script.append("textInput.focus();");
            script.append("textInput.setInlineStyleProperty('background-color', 'Yellow');");
            script.append("}");
            ADFUtils.executeClientJavascript(script.toString());
            }
            • 3. Re: Call Javascript function on ADF
              esonerdene
              Thank for reply. Now i am using "addEventListener" for my fields.
              Its working if i set clientListener on my fields directly, I mean that when not using addEventListener its return ID.
              In this situation "evt.getSource().getClientId()" return nothing and alert isn't work. I thought that that will return fields ID which i clicked.


              <af:clientListener method="funcOnLoad" type="load"/>
              <af:resource type="javascript">

              function funcOnLoad() {
              document.addEventListener('click', makeHighLight, false);
              };

              function makeHighLight(evt){           
              alert(evt.getSource().getClientId());
              }
              </af:resource>
              • 4. Re: Call Javascript function on ADF
                Suresh Karunarathne
                Hi,
                Try to set ClientListner on CommandButton and get all textFields value on that function
                • 5. Re: Call Javascript function on ADF
                  Frank Nimphius-Oracle
                  Hi,

                  your JavaScript listens for a click on the document, not necessarily the component. Even if this would do what you want, is it intended that a click on a button is highlighted too? Also what if I tab into a field? maybe you should start with the use case of what you are trying to do just to see if there is a better option

                  Frank