Search code examples
htmljsfjsf-2facelets

How do I use html5 with jsf 2 and facelets?


I'm trying to use the HTML5 doctype with jsf 2.1 and Facelets on a Glassfish 3.1.2 server.

I've seen many places that we could just replace the xhtml doctype with html5 doctype

 <!DOCTYPE html>

and leave the xmlns for xhtml in the -tag. in some forums they say that's it. But that's not it, at least Firefox doesn't agree as it render's the page as "HTML propritary" and not as HTML5.

Seems like none of the tutorials considers the html page file extension? Is this something browsers care for? I've tried to change this from *.xhtml to *.html, removing the xhtml namespace from the -tag, and in web.xml change the

 <context-param>
   <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
   <param-value>.xhtml</param-value>
</context-param>

To

 <context-param>
   <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
   <param-value>.html</param-value>
</context-param>

And added servlet mapping for html. This did not work at all.

Ok, I then reverted everything to default (xhtml/facelets), replaced only the doctype-tag and removed the xmlns referring to xhtml (from all files/templates). Now I get lot's and lot's of warnings such as these:

 Warning: This page calls for XML namespace declared with prefix li but no taglibrary   exists for that namespace.
 Warning: This page calls for XML namespace declared with prefix li but no taglibrary exists for that namespace.
 Warning: This page calls for XML namespace declared with prefix li but no taglibrary exists for that namespace.
 Warning: This page calls for XML namespace declared with prefix body but no taglibrary exists for that namespace.
 Warning: This page calls for XML namespace declared with prefix ul but no taglibrary exists for that namespace.
 Warning: This page calls for XML namespace declared with prefix form but no taglibrary exists for that namespace.
 Warning: This page calls for XML namespace declared with prefix a but no taglibrary exists for that namespace.
 Warning: This page calls for XML namespace declared with prefix a but no taglibrary exists for that namespace.
 Warning: This page calls for XML namespace declared with prefix a but no taglibrary exists for that namespace.
 Warning: This page calls for XML namespace declared with prefix a but no taglibrary exists for that namespace.

Ok, this did not look promising. In web.xml i changed the project stage from development to production.

 <context-param>
     <param-name>javax.faces.PROJECT_STAGE</param-name>
     <param-value>Production</param-value>
 </context-param>

The warnings disappeared, and w3c's validator says this is valid html5.

Does anybody have a better solution to this? Does jsf/facelets demand the files to have the extension xhtml?


Solution

  • Warning: This page calls for XML namespace declared with prefix (...) but no taglibrary exists for that namespace.

    You need to declare the XML namespace defining the HTML elements as a global XML namespace.

    That is,

    <html xmlns="http://www.w3.org/1999/xhtml">