Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make JSP tag files NOT ignore all whitespace?

I'm really stumped on this one. I want to output a list and have the tag file take care of commas, singular versus plural, etc. but when I display the list it completely ignores whitespace so everythingrunstogetherlikethis. I tried using the HTML entities "thinsp", "ensp" and "emsp" (I can't use "nbsp", these have to be breaking), but they're all hideously wide on IE except thinsp which is way too skinny on everything else.

Edit: won't work. The output from the tag has no spaces at all. Although any content in the JSP has normal spacing. Obviously I could just put everything in the JSP but this is code that goes on multiple JSPs, so tag files would make a lot of sense.

like image 527
Tim Trueman Avatar asked Oct 28 '08 21:10

Tim Trueman


1 Answers

It's actually a bug in the EL parser which causes spaces in between EL expressions to be eaten. E.g.

${bean.foo} ${bean.bar} ${bean.waa}

would get printed as (assuming that they returns the very same String value as its property name is):

foobarwaa

I recall that this issue was reported somewhere before, but I can't seem to find it right now. As far now you can fix it by using JSTL c:out tag:

<c:out value="${bean.foo} ${bean.bar} ${bean.waa}" />

which correctly get printed as:

foo bar waa
like image 149
BalusC Avatar answered Nov 05 '22 01:11

BalusC