gpt4 book ai didi

jsf - 尝试在 EL 中连接字符串时出现 NumberFormatException

转载 作者:行者123 更新时间:2023-12-02 16:17:06 26 4
gpt4 key购买 nike

这就是我想要生成的:

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

这是我的代码:

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

由于 EL 解释器尝试将“图像/ map ”转换为数字,因此失败并出现 NumberFormatException。经过一番搜索,我发现 + 只能用于添加数字。有什么想法如何达到预期的结果吗?

最佳答案

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

关于jsf - 尝试在 EL 中连接字符串时出现 NumberFormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5993774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com