12 Replies Latest reply: Mar 8, 2011 10:33 AM by 587981 RSS

    Calling javascript from a JSFF page

    552521
      When a JSFF page loads, I want to call a javascript method, if I was going to do this with a HTML page, I would call <body onLoad="myMethod">. But JSFF doesn't have a body tag.

      Does anyone know how I would go about doing this?
        • 1. Re: Calling javascript from a JSFF page
          Frank Nimphius-Oracle
          Gareth,

          sorry, forgot to call you back on this issue. I tried to find a related OTN post, but failed. Anway, I think the solution herein was to add the

          <script></script> tag to the fragment page so it got loaded when the fragment rendered

          Frank
          • 2. Re: Calling javascript from a JSFF page
            487442
            Hi,

            I highly suggest using ExtendedRenderKit.sendScript instead, you could call that in a managed bean based on some condition or by binding the root component of your fragment in the setter method for example.


            ~ Simon
            • 3. Re: Calling javascript from a JSFF page
              677781
              try this,
              <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
                        xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
                        xmlns:f="http://java.sun.com/jsf/core">
              
                <f:verbatim>
                              <![CDATA[
                                      <script language="javascript" type="text/javascript" src="js/myJavascript.js"></script>
                                      <script language="javascript" type="text/javascript">
                                      </script>
                              ]]>
                      
                   </f:verbatim>  
               <af:panelGroupLayout binding="#{backing_SubPage.employeeGroupLayout}"
                                           id="employeeGroupLayout">
              </jsp:root>
              • 4. Re: Calling javascript from a JSFF page
                552521
                Thanks for the reply. The problem is that when the fragment is first loaded (the fragment is in a taskflow and is the final step), the javascript is never loaded. I need to do a full page refresh for the javascript to be inserted into the html source. Do you know how to get around this problem?
                • 5. Re: Calling javascript from a JSFF page
                  552521
                  Any ideas?
                  • 7. Re: Calling javascript from a JSFF page
                    677781
                    Hi GarethH,

                    Can you please email me a test workspace re-producing the problem, assuming your question is still not answered...

                    simplyadf at gmail dot com,

                    thanks,
                    simplyadf
                    • 8. Re: Calling javascript from a JSFF page
                      552521
                      Email sent:

                      I have attached a test project. Although the .NET control will not load (I have not included a test DLL), you will see that after clicking “Next” in the first fragment, the second fragment will not insert the javascript or object tag in the mark-up.
                      • 9. Re: Calling javascript from a JSFF page
                        677781
                        Hello GarethH,

                        I just replied back to your email with modified test work space , which I think what you are looking for

                        let me know how it goes on,

                        thanks,
                        simplyadf
                        • 10. Re: Calling javascript from a JSFF page
                          434563
                          Could you please publish the fix for this problem, we facing the same problem
                          • 11. Re: Calling javascript from a JSFF page
                            552521
                            In the task flow, add a method call. The method is below and "fixed-outcome" should be the the fragment that you wish to navigate to.
                                public void callMyJavaScriptFunction() {
                            
                                    System.out.println("this method will call javascript function from backing bean");
                                    StringBuffer script = new StringBuffer();
                                    ExtendedRenderKitService service =
                                        (ExtendedRenderKitService)Service.getRenderKitService(FacesContext.getCurrentInstance(),
                                                                                              ExtendedRenderKitService.class);
                            
                                    script.append("alertMePlease()");
                                    service.addScript(FacesContext.getCurrentInstance(),
                                                      script.toString());
                            
                                }
                            "alertMePlease()" is the javascript method that is located on your main page that you want to call.
                            • 12. Re: Calling javascript from a JSFF page
                              587981
                              Thanks for the above response. What if the above JavaScript function requires input parameters? How can we pass the parameters to the JavaScript function in above use case?