This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

h:selectOneMenu with html entities for selectItems

 
J Recker
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to populate a jsf dropdown list with values that contain html entities. For hutputText, you can add an escape="false" and render it correctly. However, this doesn't seem to work with h:selectOneMenu or f:selectItems. Please help, it's driving me crazy!

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either escape it before display or create a custom renderer extending MenuRenderer.
 
J Recker
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm , 'escape it before display'? Can you elaborate?
Thanks,
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where escapeHTML escapes HTML entities. You can either write it yourself or make use of Apache Commons Lang StringEscapeUtils.
 
J Recker
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow, so much for trying to figure a way to use hutputText for f:selectItems, huh? I guess I thought this would be a common enough thing that the myfaces tag library would handle it.
Thanks for the input, I appreciate it.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm, I checked the API docs of SelectItem and this constructor missed my attention: http://java.sun.com/javaee/5/docs/api/javax/faces/model/SelectItem.html#SelectItem(java.lang.Object,%20java.lang.String,%20java.lang.String,%20boolean,%20boolean) also the setEscape() method. I wonder why they are not included in the TLD.

At any way, you may find it more useful Requires at least JSF 1.2 though.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a quick test with f:selectItem and you can just use the 'escape' attribute
Too bad that it isn't mentioned in the TLD of the f:selectItem.

For f:selectItems, use the constructor or setter of the SelectItem
 
J Recker
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey, thanks for the tips! I tried using all three solutions (apache commons lang), the SelectItem constructor option, and using the setEscape method, to no avail. Here is an example of what I'm dealing with:
<code>
data comes out of the database as: Printzen & T&#248;nsberg1999 .
--What should be displaying is 'Printzen & Tonsberg1999' with the 'o' in Tonsberg being the special character of 'o' with a slash through it. As long as I am using an huputText tag with escape=false, this displays correctly. When I try to have it display in a h:selectOneMenu, it comes out Printzen & T&#248;nsberg1999 .

</code>
With all three of the above solutions, I get either: 'Printzen &amp; T&amp;#248;nsberg1999' or 'Printzen & T&#248;nsberg1999'.

Am I incorrectly assessing the problem?


 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works fine here?

I am using Mojarra 1.2_12 at Tomcat 6.0.18.

Sorry for edits, the forum engine itself has a problem with parsing HTML entities.
 
J Recker
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe i should try loading the moharra jar? I cannot get escape=false to run on WASCE.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WASCE? What is it?

Well, I said before, it just requires JSF 1.2. It doesn't matter which implementation.
 
J Recker
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's WebSphere, the community edition. It's built over top of Tomcat. http://www-01.ibm.com/software/webservers/appserv/community/
<code>
anyway, i tried what you did below, and it displays out for me too, just not with the intended display. 'Printzen &amp; T&amp;#248;nsberg1999' is supposed to display as 'Printsen &amp; Tonsberg1999', with the 'o' having a slash through it. What does display is 'Printzen &amp; T&amp;#248;nsberg1999'.

</code>

oh, and hey, you're pretty cool for helping me so much.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The application server used is irrelevant. Key point is that you should be using at least JSF 1.2. The 'escape' attribute for f:selectItem was introduced in this version.
 
J Recker
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, exactly. although, my WASCE edition doesnt like jsf 1.2 very much. Regardless, I get the results I just listed above, so I'm still stuck at the same point of the unicode character not displaying correctly. Did you get ....Tonsberg... with the line through the 'o'?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I got T√łnsberg.

About escaping: I realize that I misinterpreted the initial question and made a mistake in my first example, it shouldn't be "escapeHTML", but rather "unescapeHTML".
 
J Recker
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i didn't even notice that, i knew what you meant.

The only thing I can conclude is that something else is going on, because I put in:
<code>
<f:selectItem itemLabel="Printzen & T&#248;nsberg1999" escape="false" />
</code>
and I do not get the correct display . Something is amiss, and I cannot figure out what.
 
Lisa DeSouza
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same problem: I am trying to introduce the rupee symbol, when i do:
it displays fine
but :
does not work
where messages is a properties file and rupee=₹

however, if I used :
directly, it works.

On further investigation with Firebug, it seems the selectitem is appending a space before the text when retrieving from the properties file.

Is anyone else experiencing this problem??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic