NumberFormatException when trying to combine String in EL

This is what I am trying to create:

<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...

Here is my code:

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

This does not work with a NumberFormatException exception, because the EL interpreter is trying to convert the "images / map" to a number. After searching quite a bit, I found that + is only for adding numbers. Any ideas on how to achieve the desired results?

+3
source share
2 answers

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>

. JSP Facelets, JSTL <c:set> Facelets <ui:param>.

+13

concat JSP EL. :

<ui:repeat value="#{myBean.items}" var="item" varStatus="status">
    <h:panelGroup layout="block" styleClass="marker" style="background:transparent url(#{resource['images/map:'.concat( (status.index+1).concat('.png')]} no-repeat center top;"/>
</ui:repeat>
+2

All Articles