5

In my Facelets template I used a XHTML doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I'd like to change this to HTML5 doctype as per the general recommendation:

<!DOCTYPE html>

However, JSF threw a parsing error:

javax.faces.view.facelets.FaceletException: Error Parsing /template.xhtml: Error Traced[line: 42] The entity "nbsp" was referenced, but not declared.

The HTML &nbsp; entity is not parsed then. The entity is used as follows:

<p:menuitem value="&nbsp;My menuitem">

How is this caused and how can I solve it?

1 Answer 1

8

The HTML5 doctype has no predefined entities. It assumes that the entire document is already UTF-8 aware. In other words, you can "safely" put the real non breaking space character in the HTML5 document. However, as it's not trivial to enter it in a visible way using a regular US keyboard, it's understandable that many developers prefer using an entity for it.

Facelets in turn supports as being a XML based view technology only five predefined XML entities &lt;, &gt;, &amp;, &quot; and &apos;. The &nbsp; is not among them.

You've 2 options (apart from the 3rd option to just print the character straight in the document):

  1. Declare the &nbsp; entity yourself in the doctype:

    <!DOCTYPE html [
        <!ENTITY nbsp "&#xA0;"> 
    ]>
    
  2. Or, use the (hexa)decimal notation instead:

    &#xA0; or &#160;
    
1
  • Wow! Thank you for your answer. I've tried the 1st option and it has functioned.
    – Tony
    Feb 14, 2014 at 10:47

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.