3

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?

2 Answers 2

3

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">
Sign up to request clarification or add additional context in comments.

3 Comments

Well, if you add the xml namespace for xhtml, is it really html5? If you read my question you see that I've tried your proposed solution, but Firefox renders the page as "HTML propritary" and not as HTML5.
Tried once more to add the xmlns for xhtml, and now both Firefox and W3C says valid html5. What did you do? :D Anyway, according to this diveintohtml5.info/semantics.html html5 is always in the xhtml namespace, and therefore not necessary to use. "But elements in HTML5 are always in this namespace, so you no longer need to declare it explicitly. Your HTML5 page will work exactly the same in all browsers, whether this attribute is present or not." and facelets will always have to have *.xhtml as file extension..?
It's to keep Facelets' XML parser happy. You're free to ignore those warnings though.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.