nesting of el expressions in JSF for resource API

喜夏-厌秋 提交于 2019-12-18 03:58:05

问题


<p:graphicImage value="#{resource['images:primefaces-ui/#{car.manufacturer}.jpg']}"/>

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.


回答1:


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]}"/>

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" />

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']}"/>


来源:https://stackoverflow.com/questions/7975089/nesting-of-el-expressions-in-jsf-for-resource-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!