How to use HTML character elements inside EL in JSF?

I want to use em dash in the value attribute for the h:link component.

Here is my attempt (not valid):

 <h:link value="#{somethingHere} &mdash; #{anotherHere}"> <f:param name="identifier" value="#{somethingHere.identifier}" /> </h:link> 

The result is a FaceletsException :

 FaceletException: Error Parsing /index.xhtml: Error Traced[line: 13] The entity "mdash" was referenced, but not declared. at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:394) ... 

I know that I can use HTML binding instead, but is there a way to do this inside an EL expression? What is the right way to do this?

+4
source share
1 answer

Facelets is XML-based and is processed by the XML parser. &mdash; is an HTML object and is not recognized in XML. Only five listed on this Wikipedia page , &quot; , &amp; , &apos; , &lt; and &gt; are recognized in XML.

Facelets / XML already uses UTF-8 by default, so you can just put the actual plain / unencoded character in the template (assuming the editor can save the file as UTF-8).

 <h:link value="#{somethingHere}#{anotherHere}"> 

If for some reason this is not an option, you can instead use the numeric character reference in the format &#nnnn; , for example, how to use &#160; for presentation &nbsp; in XML. You can find the digital link in fileformat.info: Unicode Character 'EM DASH' (U + 2014)

Encodings

HTML entity (decimal) &#8212;

So this should do for you:

 <h:link value="#{somethingHere} &#8212; #{anotherHere}"> 

An alternative that should satisfy the exact error is to declare an explicit object reference in doctype.

 <!DOCTYPE html [ <!ENTITY mdash "&#8212;"> ]> 

But this is not a general recommendation / approach, since you will need to repeat this for each XML file in which the symbol is used.

+6
source

All Articles