Javascript 未在包含的Facelets页面中调用Java脚本

Javascript 未在包含的Facelets页面中调用Java脚本,javascript,jsf,facelets,jsf-1.2,Javascript,Jsf,Facelets,Jsf 1.2,我在一个(主)Facelets页面中有以下代码 <h:panelGroup rendered="true"> <ui:insert> <ui:include src="/includeSecondPage.xhtml" /> </ui:insert> </h:panelGroup> 以下是includeSecondPage.xhtml页面中的内容 &

我在一个(主)Facelets页面中有以下代码

<h:panelGroup rendered="true">  
            <ui:insert>
                <ui:include src="/includeSecondPage.xhtml" />
           </ui:insert>
</h:panelGroup>

以下是includeSecondPage.xhtml页面中的内容

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core">
<head>
<script type="text/javascript">
/* <![CDATA[ */

   function myScript () 
   {
        alert("Inside myScript");
   }

   myScript();

    /* ]]> */
</script>
</head>
<f:view>
<body>

<h:form id="secondForm">
<ui:composition>

<h:outputText value="This panel is called using Component Control Component"></h:outputText>

</ui:composition>
</h:form>
</body>
</f:view>
</html>

/*  */
在includeSecondPage.xhtml中没有调用我的Java脚本。警报框未在我的第一(主页)中弹出,其中包括第二页。Java脚本控制台中没有Java脚本错误。

在包含过程中,将丢弃
之外的任何内容。
之外的任何内容仅由Dreamweaver等可视化编辑器使用,并且实际上应仅以这样的方式表示“填充”内容,以便包含的内容在视觉上“正确”表示。如果您通过右键单击浏览器中的View Source仔细查看JSF生成的HTML输出,您会注意到HTML输出中完全没有这些部分

将包含的内容放入
中。如果您不使用可视化编辑器,那么也只需删除
之外的任何内容即可。以下是整个包含文件的外观:

<ui:composition
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <script type="text/javascript">
        // <![CDATA[

        function myScript () {
            alert("Inside myScript");
        }

        myScript();

        // ]]>
    </script>

    <h:outputText value="This panel is called using Component Control Component" />
</ui:composition>

// 
另见:

javscript通过.innerHTML插入xhtml页面(即通过ajax调用)进行解析,您需要创建一个新元素节点并将其附加到头部。根据您的答案工作。“如果您仔细查看JSF通过右键单击在浏览器中查看源代码生成的HTML输出,您会注意到HTML输出中完全没有这些部分。”是的。我注意到了这一点。