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.
You can use the EL 3.0 Stream API. For example if you have a list of strings,
In case you have a list of objects for ex. Person(firstName, lastName) and you wish to concat only one property of them (ex firstName) you can use map,
In your case you could use something like that (remove the last ',' also),
Be careful! The EL 3.0 Stream API was finalized before the Java 8 Stream API and it is different than that. They can't sunc both apis because it will break the backward compatibility.
I think this is what you want:
In this case, I had a hashmap with tab ID (key) and URL (value). The tabAttrs variable isn't set prior to this. So it just sets the value to the current value of tabAttrs ('' to start) plus the key/value expression.