3 Replies Latest reply on Mar 19, 2007 2:10 PM by Sergey Smirnov

    javascript call not work in a4j:include ??

    ed bras Newbie

      Hellu,

      I am having problems calling a javascript method from within a facelets xhtml file that is included with the a4j:include tag..
      The javascript call is included in a separate timer.xhtml file:

       <script language="Javascript">
       Count();
       </script>
      


      That is included in the start.xhtml file with the facelets ui:include tag. And that start.xhtml file is included with the a4j:include tag, like below:

       <h:panelGroup id="trafficInfoPanel">
       <a4j:include viewId="/pages/start.xhtml" /> <!-- Includes the timer.xhtml -->
       </h:panelGroup>
      


      The call to the javascript method is never made :(

      Just for testing (but that's not what I want), if I include the timer.xhtml file directly next to the start.xhtml, like below, then it does work :(

       <h:panelGroup id="trafficInfoPanel">
       <ui:include src="timer.xhtml" />
       <a4j:include viewId="/pages/start.xhtml" />
       </h:panelGroup>
      


      Can someone please tell me why this is ? and how I can make this work ?

      Btw: the javascript file that contains the method is included in the template file just like in a normal html file.


        • 1. Re: javascript call not work in a4j:include ??
          Sergey Smirnov Master

          I have checked it and did not find any problem. The script is invoked even during the ajax rre-rendering. May be you have there a wrong path to a file. Add some text to the timer.xhtml to see that it is included itself for sure.

          • 2. Re: javascript call not work in a4j:include ??
            ed bras Newbie

            He Sergey,

            Thanks for your time.

            We solved it ;)..

            The problem was that my javascript method was called but I use a method getElementById('bla') in the method. However, when the element bla is included in a a4j:include the bla id contains a prefix which is the id of the include element.
            Why is this btw?.. and is this realy necessary?

            Cheers,
            Ed

            • 3. Re: javascript call not work in a4j:include ??
              Sergey Smirnov Master

              Well, the a4j:include instead of ui:include might be used to navigate between the sub-views (for partial navigation feature) where the same id are possible. To avoid such conflict, a4j:include combines together f:view and jsp:include.

              More formal reason is a #9.2.2 of the JSF Specification:



              • When using the <jsp:include> standard action (or the JSTL <c:import> action) to compose a single view from multiple JSP pages, all JSF component custom actions in included pages must be nested inside the <f:subview> custom action from the JSF Core Tag Library (which is itself nested inside the <f:view> custom action). The <f:subview> action itself may be present in the including page (i.e. with the <jsp:include> or <c:import> action nested inside it), or in the included page.