• Post Reply Bookmark Topic Watch Topic
  • New Topic

h:outputText title ascii signs  RSS feed

 
Tomáš Kotrbatý
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i have a problem using tje simplest in JSF: h:outputText.
So maybe I am doing something bad.

"ASCII escape signs" badly display in title of h:outputText.
It is the same for all the ascii signs (& # 3 4; or & # 3 5; or & # 3 6; or & # 3 7; ...etc.).
Only the first ampersand is "translated" into ampersand and others signs are left.

This is an example for ascii sign ampersand:

This is ok both in text and title:
<h:outputText value="&" escape="false" title="&" />

This is ok in text, but bad in title (in title there are the signs "& a m p;" ):
<h:outputText value="&" escape="false" title="&" />

This is ok in text, but bad in title (in title there are the signs "& # 3 8;" ):
<h:outputText value="&" escape="false" title="&" />

Please help to find a solution how to show the ascii signs as a tooltip in a correct form or if it is possible in general.

Thanks Tomas
SFME

The same problem is here (nobody has answered to me there)
http://forums.java.net/jive/thread.jspa?threadID=152359
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main question is "why do you want to override the default escape behaviour?". If you have a backing bean with a property named "life" that returns a string value of "Beer & Skittles", that value will display just fine without overriding the escape attribute on an outputText tag.

Escape is used when you want to generate raw HTML from an output tag, and that's something I recommend doing under rare conditions, since it implies that you're not keeping your Model and View components distinct. In that case, you have to escape the ampersand in the backed property and make it return "Beer &amp; Skittles".
 
Tomáš Kotrbatý
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I did not check my message and the forum translated the ascii signs into "readable" signs.

My whole problem is:
I have ascii signs in DB:
& a m p;
& # 3 8;
etc.
the signs in DB are without spaces of course (here with spaces because the forum).

So I have this signs in my backing bean property "life".

Then I use
<h:outputText value="#{MyBean.life}" escape="false" title="#{MyBean.life}" />

And the result is, that on the screen there is good translated ascii char (from example & or " ),
but in the title of this <h:outputtext is non-translated signs: & a m p; OR & # 3 8; (without spaces).
(title is shown, when you mouseover the text).
And the title is my problem.

I hope, that it is more clear now.

Thanks Tomas.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As usual, I missed an important detail.

"title" specifies what's often known as a "tooltip" - a small pop-up pane with a bit of (hopefully) helpful text in it. It's called "title" instead of "tooltip" because the actual behavior - if any - is browser dependent. For example, text-only browsers such as lynx generally don't have a way to "mouse over" a field to get a pop-up.

What you are calling "ascii signs" are actually known as entities. They are used primarily to represent characters which cannot be type or stored in their raw form, either because of limitations in the editing programs being used or because the raw version of the character has a special meaning, such as "<" in XML.

The "escape" attribute on the h:outputText element refers to the "value" attribute. The value of outputText can be any HTML or XML and that includes all sorts of formatting. The "title" attribute doesn't allow for formatting. It has to be plain text and nothing but text. No boldfacing, underlining, italics, etc.. No divs or spans or tables. No font colors - in fact no font information at all. That's decreed by the underlying HTML standard. Although there's no actual corresponding HTML tag for h:outputText, I think the title ends up on the <span> element, if one is generated and must follow the HTML rules for the span tag.

Because of this, the value of the "title" attribure is not escaped. Instead you must do your conversion in the backing bean. Since the "get" propertly accessor returns a Unicode string and since the title attribute can only be text, this is sufficient.
 
Tomáš Kotrbatý
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for making this matter clear.

If it is a HTML standard then it is done.
I only wanted to know, if there is some side way how to solve this in jsf.
I will convert the entities in my backing bean, it is no problem.

Thanks for help.
 
Tomáš Kotrbatý
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!