3

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

A.Alessio
  • 302
  • 1
  • 13
  • This is called _mojibake_ and the solution is to ensure the charset is UTF-8 everywhere. – Mr Lister Jan 06 '20 at 08:24
  • @MrLister How can I ensure that the charset is everywhere? To where should I add it and in what form? – A.Alessio Jan 06 '20 at 08:47
  • It's not easy giving specific pieces of advice, since you have not included any code in your question, but you can start by checking the charset of the entire page. – Mr Lister Jan 06 '20 at 11:29
  • I have not included any code because the project is very complex and there are many html files inside html files inside html files etc (so I think it would make the question rather unclear). But I will look into this matter, thank you for advice @MrLister. – A.Alessio Jan 06 '20 at 11:44
  • @MrLister I edited the whole question based on what I tried and what the issue is now. – A.Alessio Jan 07 '20 at 11:05
  • 1
    @A.Alessio have you tried to set the Character Encoding. We use the OmniFaces CharacterEncodingFilter to set ours to UTF-8. http://showcase.omnifaces.org/filters/CharacterEncodingFilter Its a simple servlet filter you could copy the code if you don't want to bring in OmniFaces. – Melloware Jan 07 '20 at 12:01
  • Thanks for the suggestion, @Melloware, I'll look into to it! – A.Alessio Jan 07 '20 at 12:18
  • You **should** bring in omnifaces (for more than one reason ;-)) – Kukeltje Jan 07 '20 at 12:40
  • @Melloware I added the code from the page you provided ` characterEncodingFilter org.omnifaces.filter.CharacterEncodingFilter characterEncodingFilter /* ` to the `web.xml` but then errors appear in the console and the website won't even load. Is it sufficient to put the code into the xml file (from what I understood, it should be) or should I do anything else? Thank you for help and any suggestions. – A.Alessio Jan 07 '20 at 12:59
  • That should be all you have to do? – Melloware Jan 07 '20 at 16:32
  • @Melloware from what I understood from the page, yes; then I thought that I cannot use OmniFaces feature without having installed the OmniFaces, but then again I recalled a part of your comment saying _"Its a simple servlet filter you could copy the code if you don't want to bring in OmniFaces."_ , so now I am confused... Do I need to have the whole OmniFaces installed to use the feature or not? Thanks in advance, because this is my first time with OmniFaces and I am not successful at googling what to do with it and how to use it... – A.Alessio Jan 08 '20 at 07:33
  • @Melloware I installed OmniFaces and used the `CharacterEncodingFilter` according to the guide on the page, but nothing has changed, it is still not working. Do you (or anybody) have any other ideas how to fix it? From what I have read [here](https://stackoverflow.com/questions/9634230/unicode-input-retrieved-via-primefaces-input-components-become-corrupted), my only other solution seems to be reporting the bug directly to the PrimeFaces Extensions developers... – A.Alessio Jan 08 '20 at 12:10
  • Yes I meant you could copy the omniFaces source code if you didn't want to include the JAR. But i see you got that resolved. As far as reporting it to PFE yes you can report it here: https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues – Melloware Jan 08 '20 at 12:15
  • Thanks, @Melloware for your time and help. It really seems that reporting it to the developers is the only solution left... – A.Alessio Jan 08 '20 at 12:20
  • I reported it as a bug: (https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/756)[https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/756]. – A.Alessio Jan 08 '20 at 12:37

1 Answers1

3

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.

A.Alessio
  • 302
  • 1
  • 13