Search code examples
utf-8zk

ZK Textbox - Displaying wrong UTF-8 characters


my complete ZK project is UTF-8 encoded and has declared my ZUL files accordingly, but some characters are translated completely incorrectly. I use the textbox only for output, also some blanks are replaced by "Â", anyone got an idea?

ZUL File:

<?xml version="1.0" encoding="UTF-8"?> 
...
<textbox height="1000px" width="98%" id="label_article_abstract"
                                     multiline="true"  />

Event:

String abstract = "injection were 3.4 ± 2.3" 
... 
public void onEvent(Event event) throws Exception {   
            selectedIndex =  item.getIndex();    
            tb_article_abstract.setValue(abstract);
        }

Input:"injection were 3.4 ± 2.3"

Textbox shows: "injection were 3.4 ± 2.3"


Solution

  • One cause could be that you, your source code editor/file and compiler don't agree on your source code character encoding. Maybe your editor is making it UTF-8 but your compiler isn't being told.

    -encoding encoding Set the source file encoding name, such as EUC-JP and UTF-8.

    If -encoding is not specified, the platform default converter is used.

    https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html

    (The platform's default character encoding is never the one you want—unless it is exactly the one you want. It varies from machine to machine, user to user and time to time. UTF-8 is a great choice for new work.)

    And despite what you have put the question, it appears that the spaces around the ± are NO-BREAK SPACE (U+00A0), which typographically makes a lot of sense.