在JSF中将el表达式嵌套为资源API [英] nesting of el expressions in JSF for resource API
问题描述
<p:graphicImage value="#{resource['images:primefaces-ui/#{car.manufacturer}.jpg']}"/>
我想先计算内部el,然后使用资源API计算路径.
我尝试了<c:set>
标记,但是它的变量也是EL,因此它没有任何区别.
I would like to calculate the inner el first and then calculate the path using resource API.
I tried <c:set>
tag but its variable is also an EL, so it does not make any difference.
推荐答案
在当前的EL 2.2版本中,不能以这种方式嵌套EL表达式或String-concatenate EL变量.使用 <c:set>
来通过简单地将EL表达式内联到字符串中,可以在将其用于另一个EL表达式中之前准备好动态键:
In the current EL 2.2 version, you cannot nest EL expressions nor String-concatenate EL variables that way. Use <c:set>
to prepare the dynamic key before using it in another EL expression by simply inlining the EL expression in a string:
<c:set var="resourceName" value="images:primefaces-ui/#{car.manufacturer}.jpg" />
<p:graphicImage value="#{resource[resourceName]}"/>
一种替代方法是简单地使用library
和name
属性,而不是通过#{resource}
映射基于这些属性生成URL:
An alternative is simply using library
and name
attributes instead of generating an URL based on those via #{resource}
mapping:
<p:graphicImage library="images" name="primefaces-ui/#{car.manufacturer}.jpg" />
更新:从EL 3.0开始,如果由于某些原因确实不能使用library/name
,则可以使用+=
运算符对EL变量进行字符串连接.
Update: since EL 3.0, you can use the +=
operator to String-concatenate EL variables, if you really can't use library/name
for some reason.
<p:graphicImage value="#{resource['images:primefaces-ui/' += car.manufacturer += '.jpg']}"/>
这篇关于在JSF中将el表达式嵌套为资源API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!