views:

67

answers:

2
+1  Q: 

JSF2 and Facelets

Hi all

I have tried to port JSF 1 + JSP to JSF 2 + Facelets but I have stumbled onto this error when I viewed the page in the web browser:

XML Parsing Error: no element found
Location: http://localhost/index.xhtml
Line Number 1, Column 1:

The codes of index.xhtml are:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:h="http://java.sun.com/jsf/html"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
 <h:head>
  <title><ui:insert name="title">Default title</ui:insert></title>
  <ui:insert name="metaHeader">
   <ui:include src="../includes/inc_headers.xhtml"/>
  </ui:insert> 
 </h:head>
 <h:body>
  Testing
 </h:body>
</html>

The codes of inc_headers.xhtml are:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
 <ui:define name="metaHeader">
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  <link rel="stylesheet" type="text/css" media="screen" href="../stylesheets/main.css"/>
 </ui:define>
</ui:composition>

Can anyone see the obvious problem(s) in the codes?

Thanks

A: 

Sounds like that your XML parser is extremely strict. Add the following to top of index.xhtml and retry:

<?xml version="1.0" encoding="UTF-8"?>

If that solves the problem, I'd like to know what XML parser you're using (the default JAXP instance).

BalusC
A: 

Thanks, BalusC. I tried your suggestion but still got the same error.

I'm using Eclipse Helios edition and Tomcat 6. The error I got is from Mozilla Firefox web browser.

Also, I have this setting so I can use it to troubleshoot but nothing was logged:

facelets.DEVELOPMENT true

Solved it. It was just a misconfiguration in the web.xml file that causes the error message above. I wish the error could have been less cryptic so I can troubleshoot and solve it earlier.