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?
-
2Related (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 declared](http://stackoverflow.com/questions/13012327/error-parsing-page-xhtml-error-tracedline-42-the-entity-nbsp-was-referenc) – BalusC Mar 04 '15 at 09:04
10 Answers
this will work
<h:outputText value=" " />

- 5,686
- 9
- 37
- 53
-
7
-
1Indeed, using the HTML numbers and not other html-shortcuts is the way to go. – Dnl Mar 24 '20 at 16:07
Putting the HTML number directly did the trick for me:
 

- 803
- 8
- 10
-
Oh, I just wanna give the answer right now. Glad, I have not overseen yours. – alexander Jun 16 '16 at 21:00
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" />

- 2,222
- 2
- 26
- 39
-
+1 althoug this wasn't exactly asked here, but your answer was helpful to me (regaring the title) – stacker Dec 11 '10 at 18:44
-
6
Eventually, you can try this one, if just using
fails...
<h:outputText value="& nbsp;" escape="false"/>
(like Tom, I added a space between &
and nbsp;
)

- 79,475
- 49
- 202
- 273
-
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. – Dnl Mar 24 '20 at 16:06
I found that the parser would complain if I used the
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
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

- 3,297
- 5
- 35
- 50
You can use primefaces
library
<p:spacer width="10" />

- 355
- 4
- 10
-
This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/11637485) – Luca Detomi Mar 17 '16 at 11:54
-
@ihebiheb was take +6, dont tell me it's wrong, because i know its true, just you say blah blah.. – Mohamed Aymen Charrada Mar 21 '16 at 13:18
-
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. – Luca Detomi Mar 22 '16 at 08:14
just to add to options: <h:outputText value="&nbsp;" escape="false"/>
worked

- 635
- 10
- 16
-
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. – Dnl Mar 24 '20 at 16:05
Not necessary to give 160 . 141 will also work. For the value field provide value="" .

- 117
- 1
- 3