Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:40:38+00:00 2026-06-15T16:40:38+00:00

I am creating my first facelets/JSF application. In my first page I added a

  • 0

I am creating my first facelets/JSF application. In my first page I added a facelet template:

<?xml version="1.0" encoding="ISO-8859-1" ?>
  <!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:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> 
<f:view>
  <h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Insert title here</title>
  </h:head>
  <body>
    <ui:insert name='top'>
      <ui:include src="/templates/template_a.xhtml"></ui:include>
</ui:insert>
  </body>
</f:view>
</html>

This is my template page:

  <?xml version="1.0" encoding="ISO-8859-1" ?>
  <!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:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
  <h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Insert title here</title>
  </h:head>
  <body>
    <ui:composition template="/inwert_a.xhtml">
      <ui:define name="top">
      <h2>naglowek</h2>
    </ui:define>
  </ui:composition>
</body> 
</html>

But when I look at page source in my web browser I see this:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Insert title here</title>
  </head>
  <body>
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>Insert title here</title>
      </head>
      <body>
        <h2>naglowek</h2>
      </body>
    </html>
  </body>
</html>

Why does JSF create a body and other HTML tags twice when I am using <ui:composition>?


After update my code looks that-main page:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<!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:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> 

 <h:head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
  <title>Insert title here</title> 
 </h:head> 
 <h:body>   
    <f:subview id="a">
        <ui:insert name="top">
           <ui:include src="aaa.xhtml" ></ui:include> 
        </ui:insert>
     </f:subview>
 </h:body> 
 </html>

template content:

<ui:composition 
 xmlns:ui="http://java.sun.com/jsf/facelets" 
 xmlns:h="http://java.sun.com/jsf/html"
 template="/mainpage.xhtml"
> 
  <ui:define name="top">
       <h2> aaaaaaaaa </h2>
  </ui:define>  

 </ui:composition>

this is source view:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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">

 <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
<title>Insert title here</title></head>
 <body>

 <?xml version="1.0" encoding="ISO-8859-1" ?>     
 <!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">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
<title>Insert title here</title>

</head>
 <body>
    <h2>aaaaaaaaa</h2>
 </body> 
</html>
</body> 
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:40:39+00:00Added an answer on June 15, 2026 at 4:40 pm

    You’re basically using templating the wrong way. You’re basically using them "the other way round" from how it’s supposed to be done. The page which you called "my template page" should be opened by its URL in the browser, not the page which you called "a facelet template". Best to prevent this mistake in the future is to store pages which you specify in <ui:composition template> (and <ui:include src>) inside /WEB-INF folder, so that they can never be opened directly by accident (or by hackers).

    Here’s a kickoff example which should work for your case:

    /WEB-INF/templates/template.xhtml:

    <!DOCTYPE html>
    <html lang="en"
        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">
        <h:head>
            <title><ui:insert name="title">Default title</ui:insert></title>
        </h:head>
        <h:body>
            <ui:insert name="top">
                <ui:include src="/WEB-INF/templates/top.xhtml">
            </ui:insert>
        </h:body>
    </html>
    

    /WEB-INF/templates/top.xhtml:

    <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">
        <p>Some default content for top</p>
    </ui:composition>
    

    /page.xhtml

    <ui:composition template="/WEB-INF/templates/template.xhtml"
        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">
    
        <ui:define name="title">
            New page title here
        </ui:define>
    
        <ui:define name="top">
            <h2>naglowek</h2>
        </ui:define>
    </ui:composition>
    

    Now, you should in your browser navigate to /page.xhtml (and thus not the template file).

    See also:

    • How to include another XHTML in XHTML using JSF 2.0 Facelets?
    • Which XHTML files do I need to put in /WEB-INF and which not?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just finished creating my first major application in C#/Silverlight. In the end the
I'm creating my first application and I have a window consisting of multiple subclasses
I'm creating my first Windows Phone 7 application, and I'm struggling to find an
I'm creating my first web application and I'm really confused as to what technology
Just creating my first IntelliJ web application that runs on tomcat. The project ran
So I am creating my first opengl es application on the iphone. I want
I'm creating my first web application - a really simplistic online text editor. What
Hi I am creating my first WPF application that uses Ribbons. The problem I
I'm creating my first N-Tier MVC application and I've run into a road block
I am creating my first, very simple RMI client-server application. Here is the code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.