PrimeFaces Extensions CKEditor:尝试将编码设置为UTF-8不成功。

huangapple go评论70阅读模式
英文:

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

问题

为什么我使用这个编辑器:

在过去,我使用了PrimeFaces的p:editor,但它已经被弃用,并且缺少用户急需的功能。我不能使用新的PrimeFaces p:textEditor,因为有这个问题:https://stackoverflow.com/questions/59395378/primefaces-texteditor-converting-text-to-html-with-javascript-not-working。

它用于什么:

我在我的程序中使用了来自PrimeFaces Extensions的pe:ckEditor,用户可以使用该编辑器创建电子邮件消息内容。然后,点击发送按钮,将来自编辑器的HTML通过电子邮件发送给客户。

问题是什么:

使用p:editor时,我通过JavaScript函数saveHTML获取了HTML,并且即使文本包含捷克字符(ěščřžýáíéó),它也能完美工作,我甚至不需要设置编码或其他任何内容,它都能正常工作。然而,现在用户输入 "V případě dalších dotazů se na nás můžete obracet každý den na telefonním čísle",获得的HTML文本如下:"V pÅípadÄ dalších dotazů se na nás můžete obracet každý den na telefonním Äísle" - 这显然是用户无法发送给客户的垃圾...

我的研究:

编辑:基于一些评论,我尝试添加了<meta charset="utf-8><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">,但没有帮助。在pom.xml中,我还找到了<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>,所以我认为问题不在HTML页面中,而是在编辑器本身的设置中...

因此,我想,编码必须特别为编辑器在其配置中设置。我最终弄清楚了如何让编辑器访问自定义配置,但是我在互联网上找到的并添加到配置中的所有东西都对我没有用

config.language='cs';

和:

config.entities_latin = false;

和:

config.entities = false;

和:

config.basicEntities = false;

以及它们的所有组合。

另一次编辑:

根据这里的一些其他评论,我还安装了OmniFaces,并尝试通过CharacterEncodingFilter来解决这个问题,但没有任何改变,它仍然不起作用。

我还发现我的问题似乎与这个问题非常相关:https://stackoverflow.com/questions/9634230/unicode-input-retrieved-via-primefaces-input-components-become-corrupted,但是那里的被接受的答案提供了3种解决方法,其中一种是CharacterEncodingFilter,另一种方法不适用于Tomcat用户(我),最后的“解决方法”似乎是向PrimeFaces Extensions开发人员报告此问题(我已经这样做了:https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/756)。

请告诉我如果你知道如何解决这个问题或者是否有任何解决方法。


PrimeFaces Extensions - 版本 7.0.2;
PrimeFaces - 版本 7.0.7

英文:

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: https://stackoverflow.com/questions/59395378/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: https://stackoverflow.com/questions/9634230/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

答案1

得分: 3

我和我的同事根据 @melloware 提供的测试代码找出了问题所在。<br/><br/>我们之前一直在使用的原始编辑器 p:editor,现在正试图用 pe:ckEditor 替换,只有在使用 JavaScript 函数 saveHTML 时,它才能以 HTML 格式提供内容。<br/><br/>但是,使用 pe:ckEditor 时,每当用户点击发送按钮,其 onstart 包含 saveHTML 时,saveHTML 会损坏内容。一旦我们删除了 saveHTML 并直接使用 pe:ckEditor 的内容(它已经是 HTML 格式),就不会出现损坏的字符。

英文:

I and my colleague found out what the issue was based on the test code that @melloware provided. <br/><br/>
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.<br/><br/>
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.

huangapple
  • 本文由 发表于 2020年1月6日 16:13:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定