11 Replies Last post: Apr 19, 2009 4:19 AM by Viraf Karai  
Felipe Cypriano Newbie 36 posts since
Mar 18, 2009
Currently Being Moderated

Apr 15, 2009 10:23 PM

Problems with UTF-8 encoding

Hello,

 

I'm having a annoying problem. I use IntelliJ IDEA 8.1.1 #9805 and my project is configured to use UTF-8 encoding. The problem is, I made a page (using zk framework, bu I don't it matters) to build a tree for a menu:

And the first item of the tree is:
                        <treerow>
                            <treecell label="Página Inicial"/>
                        </treerow>

 

This was working and the "á" character appears correct on the browser. But I need to to build the menu from the code to it be dynamic, so I did a java file with this:
     static {
        menuItems = new ArrayList();
        menuItems.add("Página Inicial");
    }

 

And bound the page to this menuItems, and now when the page is loaded in the browser I get this: "Página Inicial". The meta content type is set correctly to UTF-8.

It only works if I change it to menuItems.add("P\u00E1gina Inicial"), but shouldn't it be automacally done by the IDE?

 

 

Regards,

 

---
Felipe Marin Cypriano

Alexander Chernikov JetBrains 534 posts since
Jan 11, 2007
Currently Being Moderated
Apr 16, 2009 6:23 PM in response to: Felipe Cypriano
Re: Problems with UTF-8 encoding

Hello.

 

1. When your java file is opened, is "UTF-8" shown in the status bar?

2. Could you check what is the real encoding of the java source file (in some external editor, or anywhere).

3. I'm not familiar with zk. How java source is transformed into a browser page: is the source compiled, or html is generated directly from source, or ... ?

 

Alexander.

Alexander Chernikov JetBrains 534 posts since
Jan 11, 2007
Currently Being Moderated
Apr 17, 2009 7:14 PM in response to: Felipe Cypriano
Re: Problems with UTF-8 encoding

Thank you. My 3rd question was to understand, who translates "proper" java into "unproper" html. It seems we should suspect IDEA compiler. I tried simple application in 9814 (I believe, in 9805 the behavior was the same):

 

public class Speaker {
    public static void main(final String[] argv) {
        System.out.println("National chars here.");
    }
}

 

The source file is in UTF-8.

 

In 2 cases of IDEA settings combinations:

1. IDE encoding = UTF-8, project encoding = (not set).

2. IDE encoding = system default, project encoding = UTF-8.

Compiler produces proper .class file: national chars are printed correctly.

 

Is it the same for you?

 

Alexander.

Alexander Chernikov JetBrains 534 posts since
Jan 11, 2007
Currently Being Moderated
Apr 17, 2009 8:32 PM in response to: Felipe Cypriano
Re: Problems with UTF-8 encoding

> Those doesn't work:

> 1. IDE encoding = UTF-8, project encoding = not set (but the file is windows-1252, which is the system default)

 

This is correct, since a source in windows-1252 is compiled as UTF-8.

 

> 2. IDE encoding = not set (<< Systems Default>>), project encoding = UTF-8

 

And the file encoding is ... ?

 

Actually the rule is simple: make project encoding equal to file encoding, and compiler should follow. IDE encoding is used when project one is not set.

 

Alexander.

Alexander Chernikov JetBrains 534 posts since
Jan 11, 2007
Currently Being Moderated
Apr 17, 2009 9:20 PM in response to: Felipe Cypriano
Re: Problems with UTF-8 encoding

This is certainly a bug. The problem is that I cannot reproduce it.

Alexander Chernikov JetBrains 534 posts since
Jan 11, 2007
Currently Being Moderated
Apr 17, 2009 8:28 PM in response to: Felipe Cypriano
Re: Problems with UTF-8 encoding

The issue with console is possible due to unproper cmd code page and not true type console font.

You can try to compile UTF-8 source from command line and run it there: I think the effect will also be not desirable.

 

Alexander.

Viraf Karai Newbie 71 posts since
Feb 28, 2009
Currently Being Moderated
Apr 19, 2009 4:19 AM in response to: Felipe Cypriano
Re: Problems with UTF-8 encoding

So it looks like you're okay inside IntelliJ, but just to clarify, you can set the encoding for your IntelliJ project by selecting ctrl-alt-s and then selecting 'File Encodings' in the left panel (see attached screenshot).


As far as the command line, goes, try running your code as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

$ java -Dfile.encoding=UTF-8 <yourClassname>


and let us know if this makes any difference

Attachments:

More Like This

  • Retrieving data ...