使用&& EL中的错误会导致错误:实体名称必须紧跟在'&'之后在实体参考中 [英] Using && in EL results in error: The entity name must immediately follow the '&' in the entity reference

查看:122
本文介绍了使用&& EL中的错误会导致错误:实体名称必须紧跟在'&'之后在实体参考中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在jsf中使用的el表达式中使用条件表达式,但是它不起作用.

I'm trying to use a conditional expression in an el expression used in jsf, but it does not work.

<h:outputText value="#{(sel.description !=null) && (sel.description !='') ? sel.description : 'Empty description'} - "/>

但是它不起作用,编译器说:

but it does not work, the compiler says:

已跟踪错误[行:118]实体名称必须紧跟在 '&'在实体参考中.

Error Traced[line: 118] The entity name must immediately follow the '&' in the entity reference.

您有什么建议吗? 谢谢!

Do you have any suggestions? Thank you!

推荐答案

您似乎正在使用Facelets(这很好).但是,它是一种基于XML的视图技术.您在Facelets中编写的所有内容都必须是语法上有效的XML. &在XML中是一个特殊字符,表示实体的开头,例如&amp;&lt;&gt;&#160;

You seem to be using Facelets (which is perfectly fine). It's however a XML based view technology. Everything which you write in Facelets has to be syntactically valid XML. The & is in XML a special character denoting the start of an entity like &amp;, &lt;, &gt;, &#160;, etc.

如果您想按XML形式表示&,则必须将其替换为&amp;.

If you would like to represent the & as-is in XML, then you'd have to replace it by &amp;.

<h:outputText value="#{(sel.description !=null) &amp;&amp; (sel.description !='') ? sel.description : 'Empty description'} - "/>

但是,这不太容易理解,您希望为此使用替代EL运算符and(另请参见EL中的运算符以了解EL中所有可用运算符的概述):

However, that's not pretty readable, you would rather like to use the alternative EL operator and for this (see also operators in EL for an overview of all available operators in EL):

<h:outputText value="#{(sel.description !=null) and (sel.description !='') ? sel.description : 'Empty description'} - "/>

总而言之,这反过来很笨拙,因为有一个更简单的empty关键字用于测试空和空.在您的特定情况下,可以将其用作:

All with all, this is in turn pretty clumsy as there's a simpler empty keyword for the purpose of testing both nullness and emptiness. This can in your particular case be used as:

<h:outputText value="#{not empty sel.description ? sel.description : 'Empty description'} - "/>

<h:outputText value="#{!empty sel.description ? sel.description : 'Empty description'} - "/>

<h:outputText value="#{empty sel.description ? 'Empty description' sel.description} - "/>

这篇关于使用&amp;&amp; EL中的错误会导致错误:实体名称必须紧跟在'&amp;'之后在实体参考中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆