PrimeFaces Extensions CKEditor:尝试将编码设置为UTF-8失败 [英] PrimeFaces Extensions CKEditor: attempts to set encoding to UTF-8 unsuccessful

查看:164
本文介绍了PrimeFaces Extensions CKEditor:尝试将编码设置为UTF-8失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,我使用的是PrimeFaces p:editor 但是不推荐使用,并且缺少用户迫切需要的功能.由于以下原因,我不能使用新的PrimeFaces p:textEditor : a href ="https://stackoverflow.com/questions/59395378/primefaces-texteditor-converting-text-to-html-with-javascript-not-working"> Primefaces textEditor:使用JavaScript无法将文本转换为HTML .

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.

我正在使用PrimeFaces Extensions中的 pe:ckEditor 在我的程序中,用户使用其中的编辑器来创建电子邮件内容.然后,通过单击发送按钮,将获取来自编辑器的HTML,并通过电子邮件将其发送给客户端.

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.

使用p:editor时,我通过JavaScript函数saveHTML获得了HTML,即使文本包含捷克字符(ěščřžýáíéó),它也可以正常工作,我什至无需设置编码或其他任何内容,它就可以工作. 现在,当用户编写"Vpřípadědalšíchdotazůse nanásmůžeteobracetkaždýden na telefonnmčísle" 时,得到的HTML内容如下:"VpÅípadÄdalšíchdotazÅse nanás -用户显然无法发送给客户的完整垃圾...

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...

基于一些评论,我尝试添加<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页面中没有问题,但是编辑器本身的设置中有问题...

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...

所以我想,必须特别为编辑器的配置设置编码.我终于想出了如何使编辑器访问自定义配置,但是我在Internet上找不到并添加到配置中的所有内容对我来说都无效:

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';

并且:

config.entities_latin = false;

并且:

config.entities = false;

并且:

config.basicEntities = false;

及其所有组合.

另一个

基于此处的其他评论,我还安装了OmniFaces并尝试通过 CharacterEncodingFilter ,但没有任何更改,它仍然无法正常工作.

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.

我还发现我的问题似乎与以下问题非常相关: https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/756 ).

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 ).

如果您知道该如何解决或有任何解决方法,请告诉我.

PrimeFaces扩展-版本7.0.2; PrimeFaces-版本7.0.7

PrimeFaces Extensions - version 7.0.2; PrimeFaces - version 7.0.7

推荐答案

我和我的同事根据

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.

这篇关于PrimeFaces Extensions CKEditor:尝试将编码设置为UTF-8失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆