Reputation: 587
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?
Upvotes: 3
Views: 4147
Reputation: 1762
In my case, adding the namespace was not a good solution:
<html xmlns="http://www.w3.org/1999/xhtml">
The above certainly makes the Facelets parser happy, but the namespace gets written into the resulting HTML, which does not get properly detected as HTML5 by the W3C Validator.
Not using the namespace works and validates fine, but then of course there is a warning mentioned above for every plain HTML tag used in my .xhtml files.
In order to get rid of these warnings, I had to create a custom FacesContext
:
public class Html5FacesContextImpl extends FacesContextWrapper {
private final FacesContext wrapped;
public Html5FacesContextImpl(FacesContext wrapped) {
this.wrapped = wrapped;
}
@Override
public FacesContext getWrapped() {
return wrapped;
}
private final static String XML_NAMESPACE_MSG_FILTER = "Warning: This page calls for XML namespace";
@Override
public void addMessage(String clientId, FacesMessage message) {
if ( !message.getSummary().startsWith(XML_NAMESPACE_MSG_FILTER) ) {
wrapped.addMessage(clientId, message);
}
}
}
The Factory:
public class Html5FacesContextFactory extends FacesContextFactory {
private FacesContextFactory delegate;
public Html5FacesContextFactory(FacesContextFactory facesContextFactory) {
delegate = facesContextFactory;
}
@Override
public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle) throws FacesException {
return new Html5FacesContextImpl(delegate.getFacesContext(context, request, response, lifecycle));
}
}
faces-config.xml
:
<factory>
<faces-context-factory>ca.gc.agr.common.web.jsf.context.Html5FacesContextFactory</faces-context-factory>
</factory>
This seems to work.
Upvotes: 0
Reputation: 1108537
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">
Upvotes: 3