当在JSF和Primefaces中使用标题的奇怪字符时如何解决编码问题 [英] How to solve encoding problems when using strange characters of titles in JSF and Primefaces

查看:144
本文介绍了当在JSF和Primefaces中使用标题的奇怪字符时如何解决编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到编码值的问题。我正在开发一个含有西班牙语内容的网页,它使用ó,á,è等名字,或像ñ这样的字符。然后当我按下按钮保存的值,我想一个按钮的ajax事件没有采取编码,他们我添加 encoding ='ISO-8859-1',它的工作。但是我有一个自动填充的国家,在使用一个ajax事件处理信息,并为这个字段的编码不工作,之前添加 encoding ='ISO-8859-1' code>它工作。好的当解决一个,另一个失败,反之亦然。

I am in trouble with encoding values. Well I am developing a web page with spanish content, and it uses tittles like ó,á,è, etc, or characters like ñ. Then when I pressed the button to save the values, I guess the ajax event for a button didn't take the encodig, them I add encoding='ISO-8859-1', and it worked. But I have an autocomplete for countries in primefaces that also use an ajax event to proccess information, and for this field the encoding doesn't work and before to add encoding='ISO-8859-1' it worked. Well when solve one, the other one failed, and vice versa.

发生,我需要国家查阅州和列出他们。

Happen that I need the country to consult the states and list them.

网络代码:

<p:autoComplete id="pais" value="#{personal.pais}"   
                    completeMethod="#{personal.listPaises}" forceSelection="true" required="true" effect="fade" scrollHeight="400" 
                    var="p"  itemLabel="#{p}" itemValue="#{p}" requiredMessage="Es necesario seleccionar país" label="País" validator="#{personal.validatePaises}" >
                     <p:column style="width:80%" >  
                      #{p} 
                      </p:column>
                    <p:ajax event="itemSelect" update="departamento" />  
                 </p:autoComplete>

Java代码:

public void setPais(String pais) {
        int codPais = pDao.getPaisCod(pais); 
        departamentosList = pDao.listDepatamentosByPais(codPais);
        this.pais = pais;
    }

例如,如果我选择España jsf形式,在bean中被视为 Espa±a

For example if I choose España as Country in jsf form, in the bean is taken as Espa±a.

我需要统一编码。

非常感谢。

推荐答案

8,它将支持任何字符,更重要的是,它是唯一的编码,一切都有共同点。通常,某些东西只适用于UTF-8,例如许多JSON实现。如果不是这样,JSON不能支持ISO-8859-1。

You should just use UTF-8, it will support any character and more importantly it is the only encoding that everything has in common. Often something will only work with UTF-8, such as many JSON implementations. And when that isn't the case, JSON cannot support ISO-8859-1 anyways.

例如,primface的Ajax使用jQuery.param,它使用 encodeURIComponent ,它使用基于UTF-8

For instance, primeface's Ajax uses jQuery.param, which uses encodeURIComponent, which uses URL encoding that is based on UTF-8.

所以如果你想统一编码,UTF-8是你唯一的选择。

So if you want to unify encoding, UTF-8 is your only option.

Btw,使用UTF-8,我不是只是把UTF-8放在一个随机的地方似乎是正确的,但实际上确保UTF-8是声明和物理编码无处不在你的项目。

Btw, by "use UTF-8", I don't mean just to put UTF-8 in a random place that seems right but actually ensure UTF-8 is the declared and physical encoding everywhere in your project.

这篇关于当在JSF和Primefaces中使用标题的奇怪字符时如何解决编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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