Monday, April 30, 2007

cvc-elt.1: Cannot find the declaration of element 'faces-config'

If you get this error while trying to deploy JavaServer Faces (JSF)-based applications, just make sure your faces-config.xml configuration file has the reference:
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
I think the DTD version might have changed (to 1.2?) since I last used the reference implementation from Sun. This is a surprisingly common problem for people just starting out with JSF. A few books I have reviewed don't mention that configuration files (including web.xml) are validated by the container during deployment.

3 comments:

Bruno said...

I came across the same problem 5 minutes ago with 1.2 on Glassfish v2. Here's the incantation to resolve it, no DTD but a reference to the XML schema and no DOCTYPE:

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

Ganesh Jegadheesan said...

Temporary fix: Add the following context parameter to your web.xml so that faces-config initialization is done without xml validation


com.sun.faces.validateXml
false

Ganesh Jegadheesan said...

<context-param>
<param-name>
com.sun.faces.validateXml</param-name>
<param-value>false</param-value>
</context-param>