How do I insert non breaking space character   in a JSF page?
Asked Answered
T

10

91

How do I insert a non breaking space character in JSF page like I can in HTML using  ? Is there such a tag in JSF?

Turnspit answered 31/8, 2009 at 7:19 Comment(1)
Related (and technically a duplicate with a way much better explanation): Error Parsing /page.xhtml: Error Traced(line: 42) The entity “nbsp” was referenced, but not declaredMyrmeco
T
187

this will work

<h:outputText value="&#160;" />
Thyratron answered 31/8, 2009 at 9:53 Comment(2)
Why is a <h:outputText> required?Licastro
Indeed, using the HTML numbers and not other html-shortcuts is the way to go.Hashim
E
53

Putting the HTML number directly did the trick for me:

&#160;
Esque answered 8/3, 2010 at 0:32 Comment(1)
Oh, I just wanna give the answer right now. Glad, I have not overseen yours.Licastro
M
19

If your using the RichFaces library you can also use the tag rich:spacer which will add an "invisible" image with a given length and height. Usually much easier and prettier than to add tons of nbsp;.

Where you want your space to show you simply add:

<rich:spacer height="1" width="2" />
Matchless answered 1/9, 2009 at 7:4 Comment(2)
+1 althoug this wasn't exactly asked here, but your answer was helpful to me (regaring the title)Propagation
same here, this tag also exists in PrimeFaces: <p:spacer />Amah
H
9

You can also use primefaces <p:spacer width="10" height="10" />

Harwin answered 27/12, 2013 at 9:25 Comment(0)
C
7

Eventually, you can try this one, if just using &nbsp; fails...

<h:outputText value="& nbsp;" escape="false"/>

(like Tom, I added a space between & and nbsp; )

Capernaum answered 31/8, 2009 at 7:29 Comment(1)
I feel escaping is such of importance, that this might give way to non-secure solutions. Giving up escaping for only a nbsp / other html elements is tricky. Besides, the 'space' might be forgotten. This is quite verbose, while there are shorter alternatives.Hashim
S
4

I found that the parser would complain if I used the &nbsp; entity in my page. After a little research, I learned that if I added a DOCTYPE declaration to the beginning of the page, the entity was allowed. I use this DOCTYPE declaration:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

A side effect of this is that the resulting code (as seen by using the "view source" feature of a web browser) doesn't actually contain the &nbsp; entity. It instead includes the actual characters that represent a nonbreaking space. Although it works, it's not really what I want. I'm still looking for a way to make the parser not replace the entity with the character.

More information here: http://java.net/jira/browse/JAVASERVERFACES-1576

Stockbreeder answered 4/5, 2012 at 19:4 Comment(0)
A
3

The easiest way is:

<h:outputText value=" " />
Apothecium answered 20/11, 2011 at 1:5 Comment(2)
It is not the easiest way, in my opinion.Licastro
That's a regular space, not a NBSP.Length
U
3

You can use primefaces library

 <p:spacer width="10" />
Umbrageous answered 15/3, 2016 at 11:43 Comment(3)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewGaddi
@Harwin was take +6, dont tell me it's wrong, because i know its true, just you say blah blah..Umbrageous
Your answer was flagged as too short because it lacks details. I suggest you to add details to let users understand "why" your solution could be a good one or maybe the best one. Adding detailslet users adapt your solution to slightly different problems.Gaddi
A
1

just to add to options: <h:outputText value="&amp;nbsp;" escape="false"/> worked

Almaraz answered 4/3, 2015 at 14:44 Comment(1)
I feel escaping is such of importance, that this might be give way to non-secure solutions. Giving up escaping for only a nbsp / other html elements is tricky. Besides, this is quite verbose, while there are shorter alternatives.Hashim
S
0

Not necessary to give 160 . 141 will also work. For the value field provide value="&#141" .

Seduction answered 12/7, 2018 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.