Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 469
Tony Avatar asked Feb 13 '14 12:02

Tony


1 Answers

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;
    
like image 105
BalusC Avatar answered Oct 18 '22 06:10

BalusC