<p:graphicImage value="#{resource['images:primefaces-ui/#{car.manufacturer}.jpg']}"/>
我想先计算内部 el ,然后使用资源 API 计算路径。
我试过
<c:set>
标签,但它的变量也是一个 EL,所以它没有任何区别。
最佳答案
在当前的 EL 2.2 版本中,您不能以这种方式嵌套 EL 表达式或字符串连接 EL 变量。使用 <c:set>
通过简单地在字符串中内联 EL 表达式,在另一个 EL 表达式中使用它之前准备动态 key :
<c:set var="resourceName" value="images:primefaces-ui/#{car.manufacturer}.jpg" />
<p:graphicImage value="#{resource[resourceName]}"/>
另一种方法是简单地使用
library
和 name
属性,而不是通过 #{resource}
基于这些属性生成 URL映射:<p:graphicImage library="images" name="primefaces-ui/#{car.manufacturer}.jpg" />
更新 : 从 EL 3.0 开始,您可以使用
+=
运算符字符串连接 EL 变量,如果你真的不能使用 library/name
因为某些原因。<p:graphicImage value="#{resource['images:primefaces-ui/' += car.manufacturer += '.jpg']}"/>
关于jsf - 在 JSF 中为资源 API 嵌套 el 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7975089/