简体   繁体   中英

ui:insert inside ui:include is not working

Is it possible to write <ui:insert> inside <ui:include> ? When I am trying to use <ui:define name="jsInclude"> the content is not visible. When trying this with JSF 1.2, this is working but not with JSF 2.2.

Can anyone help me in understanding what am I missing with the templates concept in JSF 2.2?

Thanks!!

Below is my code

This is the template file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

    <head>
        <title><ui:insert name="browserTitle">My Page</ui:insert></title>
        <ui:insert name="head"></ui:insert>
        <ui:include src="myIncludeFile.xhtml" />
    </head>

    <body>
        <div class="mainContent">
            <!-- START OF BODY CONTENT //-->
            <ui:insert name="body">Default Body</ui:insert>
            <!-- END OF BODY CONTENT //-->
        </div>
    </body>
</html>

This is the included file

<span xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <ui:composition>
        <ui:insert name="jsInclude"></ui:insert>
    </ui:composition>
</span>

Below is the main client page

<!DOCTYPE HTML>
<html 
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <ui:composition template="../templates/myTemplate.xhtml">

        <ui:define name="browserTitle">My Page</ui:define>

        <ui:define name="head">
            This is head
        </ui:define>

        <ui:define name="jsInclude">
            This is js include!
        </ui:define>

        <ui:define name="body">
            This is body!
        </ui:define>
    </ui:composition>
</html>

Use ui:decorate instead of ui:insert . Check this question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM