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

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

问题描述

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

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>

这会产生一个< div> 每个列表中的bean。

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

对于子列表,我希望能够连接列表中的每个条目以形成单个String,显示为< div> 标题属性的一部分。为什么?因为我们使用javascript库(mootools)将此< div> 转换为浮动工具提示,并且库转为标题进入工具提示的文本。

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.

因此,如果 $ {conf.subject} 是主题,最终我希望< div> 标题为主题:blah @ blah.com,blah2 @ blah2.com等,包含子列表的所有电子邮件地址。

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.

如何使用JSP EL执行此操作?我试图远离在jsp文件中放置scriptlet块。

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>

我只使用< c:set> 重复,引用它自己的值,追加/连接字符串。

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

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

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