Text Charset Encoding

43 views
Skip to first unread message

tmuller

unread,
Jul 6, 2006, 12:51:41 PM7/6/06
to Google Web Toolkit
Hi,
how i can adjust the components text charset encoding?

Exemple:
by default its assumes "charset=UTF-8", but i need to set the charset
to "iso-8859-1" (i am from Brazil ;) ), because UTF-8 losts character
acentuation.

Thats it, thanks in advance!

darkman97

unread,
Jul 6, 2006, 2:04:44 PM7/6/06
to Google Web Toolkit
UTF-8 is more generic than ISO-8859-1 and I think is better option if
you plan future internazionalization, ISO-8859-1 is more restrictive.
UTF-8 not lost especial characters if it's well implemented.

Something that you could look :
1- Verify if really the browser recives correct webserver codification
like UTF-8 test charset browser codification you recive ( or is asuming
other ).
2- Be sure that the code editor you're using , writes files on UTF-8 (
if you're on windows environment is a normal isue that editor not makes
it, on linux files are normally writen on UTF-8 ).

If you want to set ISO-8859-1 charset I think on index.html page ( or
your GWT entry page ) put <meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1" />

tmuller

unread,
Jul 6, 2006, 6:35:09 PM7/6/06
to Google Web Toolkit
Right. The steps 1 and 2 are ok.
On may page i have:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

and in the java class file i set text of components:
<code>
final Button button = new Button("Olá");
final Label label = new Label();
label.setText("Acentuação");
</code>

The browser (firefox) responses:
Ol? (on button)
Acentua??o (on label)

i have tried setting:
<code>
final Button button = new Button("Ol&aacute;");
final Label label = new Label();
label.setText("Acentua&ccedil;&atilde;o!");
</code>

Browser responses:
Olá (corretly!)
Acentua&ccedil;&atilde;o! (wrong!)

can you help me?
Thanks for reply!

darkman97

unread,
Jul 7, 2006, 12:50:13 PM7/7/06
to Google Web Toolkit
On Label label.setText((New HTML("Acentua&ccedil;&atilde;o!")).getHTML)
I think it could run well if looks on Label implementation and HTML
you'll see are different (it's useful to see implementation class to
take code feeling ), I'm not sure it runs, i've not tested. Really I
create label object directly with extended characters :

// on Label.class
public void setText(String text) {
DOM.setInnerText(getElement(), text);
}

//on HTML.class
public void setHTML(String html) {
DOM.setInnerHTML(getElement(), html);
}

But I continue thinking is other problem on your environment. I'm sure
UTF-8 runs properly ( I've tested on english, spanish and japanese )
and runs well.

Something like this, new Button("ábcdéfg") must run correctly.
Usually when you receive something on webserver (and webserver sends
encoded on UTF-8 or other ) and the charsets ara incorrectly on browser
is originated by bad write code files ( or some configuration on the
web server ).

On way to test it, is to make simply .jsp file with extended
characters and bottom code, if it runs the editor and webserver
probably are well

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

I hope it could be useful

tmuller

unread,
Jul 10, 2006, 1:51:43 PM7/10/06
to Google Web Toolkit
ok! i will test it! i think it will work.
When i get a solution i will post it here.

Thank you very much for your attention!

tmuller

unread,
Jul 12, 2006, 7:43:21 PM7/12/06
to Google Web Toolkit
....
final Button button = new Button();

final Label label = new Label();

button.setText(new HTML("Ol&aacute;").getHTML());
DOM.setInnerHTML(label.getElement(), "Acentua&ccedil;&atilde;o!!");
....

Both methods worked fine!
Some people are looking how display chinese characters... i sugest read
this topic. If you know how to do that post the solution here:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/98d3608bad1d14ba

Thank you for your help!

tmuller

unread,
Jul 12, 2006, 7:47:54 PM7/12/06
to Google Web Toolkit
before i forget:
in the JSP file i put:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

and

Reply all
Reply to author
Forward
0 new messages