问题描述
我想在h:link
组件的value属性中使用 em破折号.
I want to use the em dash in a value attribute for an h:link
component.
这是我的尝试(目前无法正常工作):
Here is my attempt (currenctly not working):
<h:link value="#{somethingHere} — #{anotherHere}">
<f:param name="identifier" value="#{somethingHere.identifier}" />
</h:link>
这将导致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)
...
我知道我可以改用HTML锚,但是有没有办法在EL表达式中使用它呢?正确的方法是什么?
I know I can use an HTML anchor instead, but is there a way to do it inside an EL expression? What is the correct way to do this?
推荐答案
Facelets是基于XML的,并由XML解析器进行处理. —
是HTML实体,不能用XML识别.在此Wikipedia页面,"
,&
,'
,<
和>
,可以用XML识别.
Facelets is XML based and processed by a XML parser. The —
is a HTML entity and not recognized in XML. Only the five listed in this Wikipedia page, "
, &
, '
, <
and >
, are recognized in XML.
Facelets/XML默认情况下已使用UTF-8,因此您只需将实际字符以纯文本/未编码的形式放置在模板中(前提是编辑器能够将文件另存为UTF-8).
Facelets/XML uses by default already UTF-8, so you could just put the actual character plain/unencoded in the template (provided that the editor is able to save the file as UTF-8).
<h:link value="#{somethingHere} — #{anotherHere}">
如果由于某种原因这不是一个选择,则可以改用&#nnnn;
格式的数字字符引用,就像使用 
表示XML中的
一样.您可以在fileformat.info中找到数字字符引用: Unicode字符'EM DASH'(U + 2014 )
If this isn't an option for some reason, then you could instead use a numeric character reference in the format &#nnnn;
, like as one would use  
to represent a
in XML. You can find the numeric character reference in fileformat.info: Unicode Character 'EM DASH' (U+2014)
所以,这应该为您做
<h:link value="#{somethingHere} — #{anotherHere}">
一种替代方法,应该更多地满足确切的错误消息,那就是在doctype中自己明确声明实体引用.
An alternative, which should satisfy the exact error message more, is to declare the entity reference explicitly yourself in the doctype.
<!DOCTYPE html [
<!ENTITY mdash "—">
]>
但这不是一般的建议/方法,因为您需要在每个使用该字符的XML文件中重复此操作.
But this isn't the general recommendation/approach as you'd need to repeat this over every single XML file wherein the character is been used.
这篇关于在JSF中如何在EL内部使用HTML字符实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!