0

I am a newbie to JSF and facelets. I am trying to create a facelets template based on this tutorial. The common.xhtml does not display any text in header/content/footer.xhtml. I've read several posts relevant to this topic on stackoverflow, and tries several different exps based on those posts, but none of them works. localhost:8080/AppName/templates/common.xhtml always a blank page but localhost:8080/AppName/templates/header.xhtml renders correctly.

Any help is appreciated. What did I miss here?

header.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!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://java.sun.com/jsf/facelets">
  <body> 
    <ui:composition>
    <h1>Default Header</h1>
    </ui:composition> 
  </body>
</html>

footer.xhtml and content.xhtml are similar so they are omitted here.

common.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!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://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
<h:head></h:head>
<h:body>
    <div id="header">
        <ui:insert name="header">
            <ui:include src="/templates/header.xhtml" ></ui:include>

I've tried the followings header.xhtml, templates/header.xhtml, ./header.xhtml, #{request.contextPath}/templates/header.xhtml but the common.xhtml still shows a blank page

     </ui:insert>
        <br></br>
    </div>
    <div id="content">
        <ui:insert name="content">
            <ui:include src="/templates/content.xhtml" ></ui:include>
        </ui:insert>
        <br></br>
    </div>
    <div id="footer">
        <ui:insert name="footer">
            <ui:include src="/templates/footer.xhtml" ></ui:include>
        </ui:insert>
        <br></br>
    </div>
</h:body>
</html>

project file structures:

WebContent
|->META-INF
|->WEB-INF
|->templates
         |-> common.xhtml
         |-> footer.xhtml
         |-> header.xhtml
         |-> content.xhtml

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
         http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         id="WebApp_ID"
         version="3.0">

  <display-name>MathTrainerJSFDemo</display-name>
  <welcome-file-list>
    <welcome-file>pages/common.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>
</web-app>
Tiny
  • 27,221
  • 105
  • 339
  • 599
Steven He
  • 21
  • 2
  • Please add India-originated tutorial sites like tutorialspoint, javabeat and roseindia to your Internet blacklist. They are all of low quality as their primary goal is generating site-advertisements income by abusing SEO techniques, not teaching right ways and best practices to eager students. Just stick to Oracle's own tutorial (or anything else which has much less ads), or buy a normal book. See also bottom of http://stackoverflow.com/tags/jsf/info for high quality links. – BalusC Oct 26 '15 at 08:05
  • Thanks for the advice. I really appreciate it. I finally figure out my mistake and able to resolve the issue. – Steven He Oct 30 '15 at 19:44

0 Answers0