Calling javaScript method with and without parameter from bean in ADF

Put your javascript method in jspx as follows:


In my example I am calling this javascript from value change listner of one checkbox.

This javascript method is setting focus in a input text field whose id is "it25" when checkbox is checked.

"pt1" is the id of page template if you have otherwise you can remove this.

     <f:facet name="metaContainer">
        <af:resource type="javascript">
        
    function show(id){
      if(id=="pt1:sbc6"){
    var comp=AdfPage.PAGE.findComponent("pt1:it25");
    comp.focus();
      }
}
        </af:resource>
      </f:facet>

We need to write the following code in value change listner of bean.

public void setFocusOnText(ValueChangeEvent vce)
      {
           boolean selectedValue = (Boolean)vce.getNewValue(); 
       System.out.println(selectedValue);
           FacesContext facesContext = FacesContext.getCurrentInstance();
           UIComponent uid = (UIComponent)vce.getSource();
           String cid=uid.getClientId(facesContext);
      System.out.println(uid);
      System.out.println(cid);
           ExtendedRenderKitService service = (ExtendedRenderKitService)Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
   if(selectedValue==true){   
           service.addScript(facesContext,"show('"+cid+"');");
          }

    }


If you wan't to call javascript function without parameter then you code should look like as follows:

    <f:facet name="metaContainer">
        <af:resource type="javascript">
        
    function show(){
    var comp=AdfPage.PAGE.findComponent("pt1:it25");
    comp.focus();
}
        </af:resource>
      </f:facet>

And the value change listner code should look like as follows:

public void setFocusOnText(ValueChangeEvent vce)
      {
           boolean selectedValue = (Boolean)vce.getNewValue(); 
       System.out.println(selectedValue);
           FacesContext facesContext = FacesContext.getCurrentInstance();
           UIComponent uid = (UIComponent)vce.getSource();
           String cid=uid.getClientId(facesContext);
      System.out.println(uid);
      System.out.println(cid);
           ExtendedRenderKitService service = (ExtendedRenderKitService)Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
   if(selectedValue==true){   
           service.addScript(facesContext,"show();");
          }

    }

Comments

Popular posts from this blog

Setting up the environment for Angular2 and Hello World Example in Angular2

Showing number of rows or row count on top and bottom of table in ADF.

Build a Simple ReactJS application using react-cli