Facelet 无法正确转换格式化货币
我在 Facelet 页面中有以下代码:
<h:inputNumber value="bean.property">
<f:convertNumber type="currency" />
</h:inputNumber
转换器是因为输入字段内可以有一种来自 bean 属性的默认值。一切都正确呈现。输入字段内的值用“€”字符呈现(例如“1.453 €”。
当我提交表单时出现错误:
"nameOfInputField" konnte nicht als ein Geldbetrag erkannt werden '304,00 â¬'
在英语中,它有点像:
"nameOfInputField" could not be regognized as an amount of money '304,00 â¬'
请看一下“€”字符。 被打印为“â”。虽然在提交表单之前它已正确呈现,但现在在错误消息和输入字段中看起来像“â”。
所有页面都以 UTF-8 编码。
它似乎 这个错误的原因是什么? 如何修复它?
提前致谢
I have the follwing code inside a facelet page:
<h:inputNumber value="bean.property">
<f:convertNumber type="currency" />
</h:inputNumber
The converter is because there can be a kind of default value inside the input field, which comes from the bean property. Everything is rendered correctly. The value inside the input field is rendered with an "€" character (e.g. "1.453 €".
When I submit the form there comes an error up:
"nameOfInputField" konnte nicht als ein Geldbetrag erkannt werden '304,00 â¬'
In english it is some like:
"nameOfInputField" could not be regognized as an amount of money '304,00 â¬'
Please have a look at the "€" character. It seems to be printed as "â¬". While it was rendered correctly before submitting the form, now it looks like "â¬" inside the error message and inside the input field.
All pages are encoded in UTF-8.
What is the reason for this error?
How can fix it?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是来自原始 UTF-8 源的 € 的典型情况,该源被错误地使用 ISO-8859-1 解码。这是一个小片段,它证明了这一点:
您可能正在谈论响应编码。您还需要设置请求编码。
要设置
GET
请求的编码(基本上:URI 编码),您需要查阅应用程序服务器特定文档。由于不清楚您使用的是哪一个,这里有一个针对 Tomcat 的示例:<连接器 URIEncoding="UTF-8"/>
。要设置POST
请求的编码,您需要创建一个简单的过滤器,它执行request.setCharacterEncoding("UTF-8")
如果为null
。更多背景信息和提示可以在 这篇文章。This is typical for the € from an original UTF-8 source which is incorrectly been decoded using ISO-8859-1. Here's a small snippet which demonstrates that:
You're likely talking about response encoding. You need to set the request encoding as well.
To set the encoding for
GET
requests (basically: URI encoding), you need to consult the appserver specific documentation. As it's unclear which one you're using, here's a Tomcat targeted example:<Connector URIEncoding="UTF-8" />
. To set the encoding forPOST
requests, you need to create a simple filter which doesrequest.setCharacterEncoding("UTF-8")
if it isnull
. More background information and hints can be found in this article.将其放在 Facelets 页面的顶部:
它将指示 Facelets 解析器。
Put this ontop of your facelets page:
It will instruct the facelets parser.