• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:set adding a newline

 
Mark Dahlerup
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I write some scriplets to generate a string with newlines and then place teh result in a textarea I get a satisifactory result (that is the values are all on newlines in the text area). When aI do the same thing with a c:set tags I get a 'single ' line in the textarea with the newline displayed literally.



displayed in textarea using scriptlet
book(1)
book(2)
book(3)
using <c:set ..>
book(1)\nbook(2)\nbook(3)

Now I assume it something very straight forward but I'm unsure of why there are the two different results ?
I have also used <c:set var="bookStr" value="${bookStr}\n" /> with the same result.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the definition of the <c:set> tag to see if there was something that could help you out?

Hint: there is.
 
Mark Dahlerup
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Bear but I must need a kick in the head
All I can find are the five attributes var, value. target, property and scope and none for them seem to me to have a solution
(http://download.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoops! My bad! I meant for you to look at <c:out> not <c:set>. The kick in the head is mine.
 
Mark Dahlerup
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear
I tried to use a cut with escapeXml as true andfalse - no change (\n not a HTML char to worry about)
<textarea cols="40" rows="${size}" readonly="readonly" ><cut value="${bookStr}" escapeXml="false" /></textarea>
 
Stefan Evans
Bartender
Posts: 1743
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The c:set tag is most probably escaping those back-slashes for you.

Here is one way of doing it:



And here are a couple of alternatives for you.
One making use of the fact that you can use the <c:set> tag with a nested body
The other getting rid of the <c:set> tag and just outputting it straight into the textarea.

The downside with both of these is that they are very sensitive to white space.
I've doctored your code a bit so that it is a stand-alone code example, so ${book.name} turned into ${book} in the example just because it was easier that way.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I thought sure it'd be the escapeXml thing, but maybe not (not anywhere where I can test...).
 
Mark Dahlerup
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ta Stefan - all worked a treat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic