This discussion is archived
12 Replies Latest reply: Mar 8, 2011 8:33 AM by 587981 RSS

Calling javascript from a JSFF page

552521 Newbie
Currently Being Moderated
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 Employee ACE
    Currently Being Moderated
    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 Expert
    Currently Being Moderated
    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 Explorer
    Currently Being Moderated
    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 Newbie
    Currently Being Moderated
    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 Newbie
    Currently Being Moderated
    Any ideas?
  • 6. Re: Calling javascript from a JSFF page
    629225 Newbie
    Currently Being Moderated
    --
  • 7. Re: Calling javascript from a JSFF page
    677781 Explorer
    Currently Being Moderated
    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 Newbie
    Currently Being Moderated
    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 Explorer
    Currently Being Moderated
    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 Newbie
    Currently Being Moderated
    Could you please publish the fix for this problem, we facing the same problem
  • 11. Re: Calling javascript from a JSFF page
    552521 Newbie
    Currently Being Moderated
    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 Newbie
    Currently Being Moderated
    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?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points