jsfprimefacescharacter-encodingckeditorprimefaces-extensions

PrimeFaces Extensions CKEditor: attempts to set encoding to UTF-8 unsuccessful


Why I am using this editor:

In the past I used PrimeFaces p:editor which is however deprecated and lacks functions that the users desperately want. I cannot use the new PrimeFaces p:textEditor because of this: Primefaces textEditor: converting text to HTML with JavaScript not working.

What is it used for:

I am using pe:ckEditor from PrimeFaces Extensions in my program, in which the editor is used by the user to create an e-mail message content. Then by click on a send button, the HTML from the editor is taken and sent via e-mail to a client.

What is the issue:

When using p:editor, I got the HTML by JavaScript function saveHTML and it worked perfectly even when the text contained Czech characters (ěščřžýáíéó), I did not even have to set enconding or anything else and it worked. Now however when user writes "V případě dalších dotazů se na nás můžete obracet každý den na telefonním čísle", the gotten HTML has the text like this:"V pÅípadÄ dalších dotazů se na nás můžete obracet každý den na telefonním Äísle" - complete rubbish that the user obviously cannot send to a client...

My research:

EDIT: Based on some comments, I tried to add the <meta charset="utf-8> and <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> but that did not help. In pom.xml I have found also this <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>, so I do not think that there is a problem in the HTML page, but in settings of the editor itself...

So I figured, that the encoding must be set especially for the editor in its config. I finally figured how to make the editor access the custom config, but nothing that I found on the Internet and added to the config worked for me:

config.language='cs';

And:

config.entities_latin = false;

And:

config.entities = false;

And:

config.basicEntities = false;

And all its combinations.

ANOTHER EDIT:

Based on some other comments here, I also installed OmniFaces and tried to solve this by CharacterEncodingFilter, but nothing changed and it is still not working.

I also found out that my problem seems to be very related to this issue: Unicode input retrieved via PrimeFaces input components become corrupted, but the accepted answer there gives 3 ways how to solve it, one is the CharacterEncodingFilter, other way is not applicable for Tomcat users (me) and the last "solution" seems to be reporting this to PrimeFaces Extensions developers (which I did: https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/756 ).

Please let me know if you know how to fix this or if there is any workaround.


PrimeFaces Extensions - version 7.0.2; PrimeFaces - version 7.0.7


Solution

  • I and my colleague found out what the issue was based on the test code that @melloware provided.

    The original editor p:editor, which we had been using and which we are trying to replace by pe:ckEditor, could provide us with its content in HTML only in case we used JavaScript function saveHTML.

    But with pe:ckEditor, anytime the user hit the Send button, whose onstart contained the saveHTML, the saveHTML corrupted the content. Once we erased the saveHTML and took the pe:ckEditor content as it was (which is already in HTML), it was fine without corrupted characters.