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

5

102

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?

Urethroscope answered 22/10, 2012 at 13:18 Comment(1)
show some more code... where idi you placed that   exactly ?Ferment
S
201

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;.

Solferino answered 22/10, 2012 at 13:27 Comment(2)
Use the hex or decimal notation. :-)Subminiature
&#xA0; solved the drifting decimal point right alignment problem when incorporated into the pattern #,##0.00&#xA0;;(#,##0.00) within a Jasper Report/Library/Studio .JRXML file.Idealistic
P
15

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">
Possessed answered 29/4, 2016 at 15:27 Comment(1)
With this I was able to do something like <xsl:variable name="size" select="substring-before(s:td[3], '&nbsp;')" />Hamlett
A
14

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

Aun answered 22/10, 2012 at 13:30 Comment(0)
E
11

Add below to the top of the file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Ey answered 25/2, 2015 at 13:49 Comment(2)
Why did this get two negatives I wonder. It's maybe a bit too concise but it is correct. The entity was not defined in the doctype and it is defined when using the spec provided. A year later, someone posts the exact same thing and gets two upvotes.Demulsify
I agree with @Dilapidus, this worked perfect for me in Chrome and JBoss EAP 7 and Facelets Version 2.2Infer
P
9
  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.

Pennate answered 13/2, 2013 at 18:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.