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.
Web code:
<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 Code:
public void setPais(String pais) {
int codPais = pDao.getPaisCod(pais);
departamentosList = pDao.listDepatamentosByPais(codPais);
this.pais = pais;
}
For example if I choose España as Country in jsf form, in the bean is taken as Espa±a.
I need unify the encodig.
Thanks a lot.
I know that my problem was with ajax request of autocomplete and commandButton.Then I tried everything and didn't work. well I solve my problem changing my jsf commandButton to Primefaces commandButton.
Before
<h:commandButton value="submit" action="Periodico?faces-redirect=true" actionListener="#{personal.insertarUsuario}" />
After
<p:commandButton value="submit" action="Periodico?faces-redirect=true" actionListener="#{personal.insertarUsuario}" />
And so I solve my problem. Thanks a lot for your time and answers
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.
For instance, primeface's Ajax uses jQuery.param, which uses
encodeURIComponent
, which uses URL encoding that is based on UTF-8.So if you want to unify encoding, UTF-8 is your only option.
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.