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

4

8

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.

Racy answered 28/10, 2008 at 21:10 Comment(0)
G
14

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
Gillmore answered 25/1, 2010 at 18:8 Comment(1)
I want to print name inside TD which has 2 spaces between like "abc de". I am printing like <c:out value="<%=name%>"/>. But getting single white space.Jetport
L
2

Maybe put the jsp content in an html <pre> tag? This seems to me to be the right thing to do as the list is pre-formatted content.

Lilli answered 28/10, 2008 at 23:53 Comment(0)
K
1

I used &#32; entity instead of space but generally I think this sucks that either ALL whitespace is eaten and one has to hack with entities or you have vast space in the generated HTML code.

Kurdish answered 25/1, 2010 at 16:7 Comment(0)
N
0

So you are saying your tag doesn't print out white space at all? Is there any whitespace for it to print out?

Can you post the code, and a short example of how you use it?

Nessi answered 18/3, 2009 at 2:26 Comment(1)
My solution was to just put all text 100% into property files. Sometimes I have to chain together things since the text is somewhat dynamic: "user1, user2 and user3 did something" for instance.Racy

© 2022 - 2024 — McMap. All rights reserved.