Dis*_*tum 3 jsf facelets el jsf-2
这就是我想要生成的:
<div class="marker" style="background:transparent url('/myApp/faces/javax.faces.resource/1.png?ln=images/map') no-repeat center top;"></div>
<div class="marker" style="background:transparent url('/myApp/faces/javax.faces.resource/2.png?ln=images/map') no-repeat center top;"></div>
<div class="marker" style="background:transparent url('/myApp/faces/javax.faces.resource/3.png?ln=images/map') no-repeat center top;"></div>
etc...
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
<ui:repeat value="#{myBean.items}" var="item" varStatus="status">
<h:panelGroup layout="block" styleClass="marker" style="background:transparent url(#{resource['images/map:'+(status.index+1)+'.png']} no-repeat center top;"/>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
这与NumberFormatException失败,因为EL解释器尝试将"images/map"转换为数字.经过相当多的搜索后,我发现+仅用于添加数字.任何想法如何达到预期的效果?
Bal*_*usC 14
EL不将+运算符识别为字符串连接运算符.+EL中的运营商最终只对数字求和.您需要使用<ui:param>创建另一个表达式变量,其中您通过在值中内联EL表达式来连接部分,然后在最终表达式中使用它.
<ui:repeat value="#{myBean.items}" var="item" varStatus="status">
<ui:param name="key" value="images/map#{status.index + 1}.png" />
<h:panelGroup layout="block" styleClass="marker" style="background:transparent url(#{resource[key]} no-repeat center top;"/>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
注意:如果您使用的是JSP而不是Facelets,那么您已经使用了JSTL <c:set>而不是Facelets <ui:param>.
| 归档时间: |
|
| 查看次数: |
5496 次 |
| 最近记录: |