Wednesday, March 31, 2010

Bit #3 - Adding Javascript to a JSPX page

The recommended way to add scripting to your JSPX page is via the metaContainer <facet> tag. You add the metaContainer <facet> within the <af:document> tag. You can group your scripts within the metaContainer <facet> using an <af:group> tag. The actual script should be added within an <afh:script> or a <trh:script> tag. Adding Javascript to your JSPX page by directly placing a <script> tag is not recommended because it could have undesired side effects related to the proper resizing of the components in the page.

Example:

<f:facet name="metaContainer">
    <af:group>
        <afh:script source="/js/YourJsLibrary.js"/>
        <afh:script>
           function someFunction()
           {
                 …
           }
        </afh:script>
    </af:group>
</f:facet>

Context:

JSPX Page

8 comments:

  1. Nice post Nick, which reminded me something that I read in Frank's new book
    ( http://www.amazon.co.uk/Oracle-Fusion-Developer-Guide-Applications/dp/0071622543/ref=ntt_at_ep_dpt_1 ).
    According to the book, the preferred way is to use af:resource tag (http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_resource.html).
    which optimizes the loading of Javascript etc (more in Frank book).

    Hope this helps too. :)

    ReplyDelete
  2. Thanks for the pointer Spyro! Also, take a look at related post Bit #1.

    ReplyDelete
  3. Respect Nick. You are always ahead of me :)

    ReplyDelete
  4. Why not af:resource inside the metaContainer facet??

    ReplyDelete
  5. George, as Spyros said in his comment, that would do as well. The approach mentioned in the post, is how we added Javascript to resolve issues related to proper resizing of components on the page. It seems to be working well.

    ReplyDelete
  6. Hi,
    Do you have any info. to read a cookie inside ADF

    ReplyDelete
  7. I need to add into my jspx page. where should I put it so that it appears under head tag . Kindly help

    Thanks in advance

    ReplyDelete
  8. Hi.. I am new to oracle jDeveloper and to Java. Can u pls let me know how to write a javascript for calling a function inside jspx page?
    TIA

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...