Error Parsing /page.xhtml: Error Traced[line: 42] The entity "nbsp" was referenced, but not declared

JsfJsf 2FaceletsHtml Entities

Jsf Problem Overview


I'd like to use non breaking spaces in my JSF page. I know, in plain HTML I could use   for this and this works fine. However, when I put those   in a Facelets page, then it errors as follows:

> Error Parsing /page.xhtml: Error Traced[line: 42] The entity "nbsp" was referenced, but not declared.

How is this caused and how can I solve it?

Jsf Solutions


Solution 1 - Jsf

Facelets is a XML based view technology. XML has only five predefined entities. The   is not among them. It works only when used in plain HTML or in legacy JSP (note: it doesn't work in JSPX as that's also XML based!).

To fix this, you either need to declare the entity yourself in the doctype of the very XHTML file containing the   entity,

<!DOCTYPE html [
    <!ENTITY nbsp "&#160;"> 
]>

or, better, use the (hexa)decimal notation instead:

&#xA0; or &#160;

In an average IDE it should be trivial to perform a "find and replace in all files" and replace every occurrence of &nbsp; by &#xA0;.

Solution 2 - Jsf

Try using &amp;#160;. for more information on entities you can refer following url HTML ISO-8859-1 Reference

Solution 3 - Jsf

For me the following doctype enables &nbsp;:

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

Solution 4 - Jsf

  1. <![CDATA[&nbsp;]]> should work fine. This does not work inside attribute value, though.

  2. Alternatively, as long as &amp; is a predefined entity in XML, you could try &amp;nbsp; - worked for me with XML based JSP. This should work within attributes as well.

Solution 5 - Jsf

add

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

to the top of the file

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFahim ParkarView Question on Stackoverflow
Solution 1 - JsfBalusCView Answer on Stackoverflow
Solution 2 - JsfSanjeevi.VView Answer on Stackoverflow
Solution 3 - JsfOleg KhaschanskyView Answer on Stackoverflow
Solution 4 - JsfPeter and the WolfView Answer on Stackoverflow
Solution 5 - JsfИгорь ДолгополовView Answer on Stackoverflow