ui:insert inside ui:include is not working

3.3k views Asked by At

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

There are 1 answers

0
Mohamed Wagdy Khorshid On

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