Garbage in p:editor text containing HTML character entities

UI Components for JSF
Post Reply
krahe
Posts: 52
Joined: 09 Nov 2011, 19:13
Location: Rockford, Michigan, USA
Contact:

15 Jan 2015, 19:39

I am trying to use p:editor to edit text that may contain character entities like < or &reg;. The problem is that when a string edited by the user in a p:editor is returned to the backing bean, the character entity is replaced by the actual character it represents, plus a garbage character. For example, an original string obtained from a database might be:

Code: Select all

<h1 style="[%h1]">ENERGY STAR<sup>&reg;</sup> Performance Rating<br></h1>
After a simple edit like removing one letter from the last word, the string returned to the backing bean is:

Code: Select all

<h1 style="[%h1]">ENERGY STAR<sup>®</sup> Performance Ratng<br></h1>
Upon subsequent retrieval from the database, the special character is back in its original form, but the garbage character remains:

Code: Select all

<h1 style="[%h1]">ENERGY STAR<sup>&#194;&reg;</sup> Performance Ratng<br></h1>
The problem simply continues, with another garbage character added each time the value is edited. For instance, deleting another character results in:

Code: Select all

<h1 style="[%h1]">ENERGY STAR<sup>�®</sup> Performance Ratg<br></h1>
I don't know if this is a problem with p:editor or if something else is to blame. I'm using PrimeFaces 4.0.24, but the behavior seems to be the same with version 5.1.8.

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

16 Jan 2015, 11:17

This looks like a problem with encoding.
The application looks like it is expecting ISO-8859-1 (or some other non-UTF-8 encoding) but is actually receiving UTF-8 encoded values.
Either that or there is a filter doing something weird to the characters in the request parameter values.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

krahe
Posts: 52
Joined: 09 Nov 2011, 19:13
Location: Rockford, Michigan, USA
Contact:

16 Jan 2015, 17:51

It must have been an issue with my application server (GlassFish 4.1). I had to reinstall my application on a different server, and when I run my app under GlassFish 4.1 with the latest updates (the old server's code was a bit out of date), the problem went away.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 50 guests