0

1つの(メイン)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スクリプトが呼び出されません。この2番目のページを含む最初の(メイン)ページにアラートボックスがポップアップしません。また、JavaスクリプトコンソールにはJavaスクリプトエラーはありません。

4

1 に答える 1

2

インクルード中は、外部の<ui:composition>ものはすべて破棄されます。外部のコンテンツ<ui:composition>は、Dreamweaverなどのビジュアルエディターによってのみ使用され、実際には、インクルードコンテンツが「適切に」視覚的に表現されるように、「塗りつぶし」コンテンツのみを表現する必要があります。JSFで生成されたHTML出力を右クリックして[ブラウザでソースを表示]を見ると、これらの部分がHTML出力に完全に含まれていないことに気付くでしょう。

インクルードコンテンツをに入れ<ui:composition>ます。ビジュアルエディタを使用していない場合は、外部のものも削除して<ui:composition>ください。インクルードファイル全体は次のようになります。

<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>

参照:

于 2013-02-14T11:34:10.450 に答える