在 JSP EL 中连接字符串? [英] Concatenate strings in JSP EL?

查看:49
本文介绍了在 JSP EL 中连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 bean 列表,每个 bean 都有一个属性,它本身就是一个电子邮件地址列表.

<div class='scheduled' title="${conf.subject}" id="scheduled<c:out value="${conf.id}"/>">...

</c:forEach>

这会为列表中的每个 bean 渲染一个

.

对于子列表,我希望能够将列表中的每个条目连接起来形成一个字符串,作为<div>的一部分显示

code> 的 title 属性.为什么?因为我们用的是一个javascript库(mootools)把这个

变成了一个浮动的工具提示,这个库把title变成了工具提示的文本.

所以,如果 ${conf.subject} 是主题",最终我想要

title> 为主题:blah@blah.com、blah2@blah2.com 等",包含子列表的所有电子邮件地址.

如何使用 JSP EL 执行此操作?我试图避免将 scriptlet 块放在 jsp 文件中.

解决方案

想出了一个有点脏的方法:

<c:set var="title" value="${conf.subject}:"/><c:forEach items="${conf.invitees}" var="invitee"><c:set var="title" value="${title} ${invitee}, "/></c:forEach><div class='scheduled' title="${title}" id="scheduled<c:out value="${conf.id}"/>">...

</c:forEach>

我只是重复使用 ,引用它自己的值,来附加/连接字符串.

I have a List of beans, each of which has a property which itself is a List of email addresses.

<c:forEach items="${upcomingSchedule}" var="conf">
    <div class='scheduled' title="${conf.subject}" id="scheduled<c:out value="${conf.id}"/>">
    ...
    </div>
</c:forEach>

This renders one <div> per bean in the List.

For the sublist, what I'd like to be able to do is to concatenate each of the entries in the list to form a single String, to be displayed as a part of the <div>'s title attribute. Why? Because we are using a javascript library (mootools) to turn this <div> into a floating tool tip, and the library turns the title into the text of the tooltip.

So, if ${conf.subject} was "Subject", ultimately I'd like the title of the <div> to be "Subject: blah@blah.com, blah2@blah2.com, etc.", containing all of the email addresses of the sub-list.

How can I do this using JSP EL? I'm trying to stay away from putting scriptlet blocks in the jsp file.

解决方案

Figured out a somewhat dirty way to do this:

<c:forEach items="${upcomingSchedule}" var="conf">
    <c:set var="title" value="${conf.subject}: "/>
    <c:forEach items="${conf.invitees}" var="invitee">
        <c:set var="title" value="${title} ${invitee}, "/>
    </c:forEach>
    <div class='scheduled' title="${title}" id="scheduled<c:out value="${conf.id}"/>">
    ...
    </div>
</c:forEach>

I just use <c:set> repeatedly, referencing it's own value, to append/concatenate the strings.

这篇关于在 JSP EL 中连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆