How can I display my list in a TestArea line after line with no additional spaces. i.e:
this
that
the
other
Here is my attempt:
<div class="text">
<label for="output_string">Output:</label> `
<textarea rows="10" cols="20">
<c:forEach var="x" items="${messagelist}">${x}</c:forEach>
</textarea>
</div>
Here’s a guess (which I’ll try out in just a sec in one of my own pages):
edit — no that doesn’t seem to work at all. However, what did work was for me to add a message catalog entry like this:
Then you can use
<fmt:message key="linebreak"><fmt:param value="${x}"/></fmt:message>to produce the string terminated by line breaks.Note that JSP will put spaces before the first entry according to the indentation in your .jsp source file before the
<c:forEach>, so you’ll have to line everything up at the left edge if you don’t want that.If I had to do this a lot, I’d write an EL add-on function of my own to echo back a string followed by CRLF.
edit — If you want to write an EL add-on, you need two things:
public staticmethod of some class. I keep a class around called “ELFunctions” for most of mine. You can arrange them any way you want.So you would write a little function like this, in some class:
Then your “.tld” file would look like this (assuming it’s the only thing you’ve got; if you have an existing “.tld” file just add the clause):
(Boy, XML is so annoying.) Now somewhere you probably already have a little file that pulls in taglibs for your pages (for
<c:...>tags at least). In there, or at the top of any page, add a line like this:I think that the JSP runtime searches for “.tld” files by looking through the WEB-INF subtree, and in .jar files in WEB-INF/lib, matching by that “uri” string. Anyway, once you’ve done that, in your JSP file you can say:
and it’ll invoke your function.