aspose file tools*
The moose likes JSP and the fly likes c:set adding a newline Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "c:set adding a newline" Watch "c:set adding a newline" New topic
Author

c:set adding a newline

Mark Dahlerup
Greenhorn

Joined: Jun 29, 2010
Posts: 8
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

Joined: Jan 10, 2002
Posts: 60053
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Dahlerup
Greenhorn

Joined: Jun 29, 2010
Posts: 8
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

Joined: Jan 10, 2002
Posts: 60053
    
  65

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

Joined: Jun 29, 2010
Posts: 8
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

Joined: Jul 06, 2005
Posts: 1016
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

Joined: Jan 10, 2002
Posts: 60053
    
  65

Hmm, I thought sure it'd be the escapeXml thing, but maybe not (not anywhere where I can test...).
Mark Dahlerup
Greenhorn

Joined: Jun 29, 2010
Posts: 8
Ta Stefan - all worked a treat
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: c:set adding a newline
 
Similar Threads
Problems with paging i created
check boxes retrieving problem
Enumeration is not returning any data
How to use Break / exist statement here in foreach (JSTL)
Pagination in jsp