aspose file tools*
The moose likes JSF and the fly likes h:selectOneMenu with html entities for selectItems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "h:selectOneMenu with html entities for selectItems" Watch "h:selectOneMenu with html entities for selectItems" New topic
Author

h:selectOneMenu with html entities for selectItems

J Recker
Greenhorn

Joined: Aug 26, 2006
Posts: 18
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

Joined: Oct 08, 2006
Posts: 2458
Either escape it before display or create a custom renderer extending MenuRenderer.
J Recker
Greenhorn

Joined: Aug 26, 2006
Posts: 18
Hm , 'escape it before display'? Can you elaborate?
Thanks,
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
where escapeHTML escapes HTML entities. You can either write it yourself or make use of Apache Commons Lang StringEscapeUtils.
J Recker
Greenhorn

Joined: Aug 26, 2006
Posts: 18
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Aug 26, 2006
Posts: 18
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Aug 26, 2006
Posts: 18
maybe i should try loading the moharra jar? I cannot get escape=false to run on WASCE.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
WASCE? What is it?

Well, I said before, it just requires JSF 1.2. It doesn't matter which implementation.
J Recker
Greenhorn

Joined: Aug 26, 2006
Posts: 18
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Aug 26, 2006
Posts: 18
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Aug 26, 2006
Posts: 18
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

Joined: Jul 21, 2009
Posts: 6
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??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: h:selectOneMenu with html entities for selectItems