• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

c:set adding a newline

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear
I tried to use a c:out with escapeXml as true andfalse - no change (\n not a HTML char to worry about)
<textarea cols="40" rows="${size}" readonly="readonly" ><c:out value="${bookStr}" escapeXml="false" /></textarea>
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ta Stefan - all worked a treat
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic