【发布时间】:2011-12-30 13:30:58
【问题描述】:
我正在尝试使用 JSF 中的统一表达式语言编写一个表达式,该表达式指出,如果图像不为空,则使用它,否则使用默认图像。
#{not empty image ? image : #{bean.directory}image.jpg}
问题是默认的只能通过调用某个函数“#{bean.directory}”来检索目录。我收到ERROR PARSING。
知道如何解决这个问题吗?
【问题讨论】:
我正在尝试使用 JSF 中的统一表达式语言编写一个表达式,该表达式指出,如果图像不为空,则使用它,否则使用默认图像。
#{not empty image ? image : #{bean.directory}image.jpg}
问题是默认的只能通过调用某个函数“#{bean.directory}”来检索目录。我收到ERROR PARSING。
知道如何解决这个问题吗?
【问题讨论】:
我不知道在 EL 中连接字符串的简单方法,所以这篇文章有点笨拙但应该可以工作(我假设 image 是某种具有完整文件名的变量,而 'image.jpg' 是您的默认文件名在 bean.directory 中查找):
#{empty image ? bean.directory : image}#{empty image ? 'image.jpg' : ''}
【讨论】:
你的错误是,你嵌套了表达式。
<NEW_EL1>not empty image ? image : <NEW_EL2>bean.directory</END_EL2>image.jpg</END_EL2>
不支持。
与你的表情有关:
#{empty image ? bean.directory : image}#{empty image ? 'image.jpg'}
另一个例子:
#{((fooBean.random % 4) == 0 ? 'completely divisible by 4' : 'not completely divisible by 4'}
【讨论】: