Encoding issue in autocomplete
cmoraes Apr 13, 2011 12:39 PMHi,
I'm trying to include an autocomplete component in my application, but I'm having some trouble with that.
If I type some accent character, as 'ção' for example ,in autocomplete field, in the server side method, I receive weird character like "ç".
I believe that is a client side issue, because it works fine in Firefox. At other hand, in Chrome and IE8, it fails.
Here the code that I'm using to test this:
autocompleteTest.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<f:view contentType="text/html" encoding="UTF-8">
<h:head>
<title>teste</title>
</h:head>
<h:body>
<h:form acceptcharset="UTF-8">
<rich:autocomplete mode="ajax" minChars="1"
autofill="false" autocompleteMethod="#{autocompleteTest.autocomplete}"
id="myAutocomplete" var="modeler"/>
</h:form>
</h:body>
</f:view>
</html>
AutocompleteTest.java
package teste;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class AutocompleteTest {
private List<String> lst;
public AutocompleteTest() { }
@PostConstruct
public void init() {
try {
lst = new ArrayList<String>();
BufferedReader in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/resource/CountryList.txt")));
String line;
while((line = in.readLine())!=null) {
lst.add(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public List<String> autocomplete(String prefix) {
System.out.println(prefix);
ArrayList<String> result = new ArrayList<String>();
if (prefix!=null && !prefix.isEmpty()){
for (String s : lst) {
if (s.toLowerCase().indexOf(prefix.toLowerCase()) == 0) {
result.add(s);
}
}
}
return result;
}
}
I'm using Glassfish3.
I thanks in advance for any help.
Cristiano