1

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>
Tiny
  • 27,221
  • 105
  • 339
  • 599
user1661892
  • 103
  • 4
  • 13
  • You need `` inside `` such as ``. Those template pages should be placed under the `WEB-INF` directory so that they are not served to clients, if they demand template pages using the corresponding URL. – Tiny Jun 22 '15 at 02:40
  • 1
    Try to change included file to ` ... ` – Vasil Lukach Jun 24 '15 at 20:44
  • I faced the same issue, I was trying to extract a header which contains lot of primefaces controls into a separate file to be more readible. I tried the 2 solutions above and both didn't work. I'll post a solution if I was able to solve it. – Mohamed Wagdy Khorshid May 09 '16 at 15:20

1 Answers1

0

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

Community
  • 1
  • 1