I need your help in displaying some Arabic text which is stored in a variable in the xhtml page. I have configured my project in jdeveloper to include UTF-8 in the properties and the Arabic text is displayed correctly. I have a variable called bankName and it has the unicode value which is :
String bankName = "\u0627\u0644\u0628\u0646\u0643 \u0627\u0644\u0645\u062a\u062d\u062f";
in the xhtml when I am printing the variable output <h:outputText value="#{hrd.bankName}" style="font-weight:bold" />
, the Arabic text is showing properly "البنك المتحد"
, however the same value of the unicode is stored in a database field and I am retrieving the value of it from the below code:
String bankName=result.getString("bank_name_arabic").trim();
The xhtml will display the Arabic text as a text:
\u0627\u0644\u0628\u0646\u0643 \u0627\u0644\u0645\u062a\u062d\u062f
in the xhtml page and will not give the value of it in Arabic.
So how can I achieve this.
This line:
Is completely equivalent to this:
Escaping (think, for example, about
\n
) isn't a mechanism in-built in Java strings. It's Java compiler that performs these replacements for you. Imagine to have a text file with these two characters: \ and n. If you read them like this:Now you can check text content: it's exactly two characters: \ and n then:
Will print:
After this introduction you should understand why it doesn't work what you're doing: you're storing an escaped string in your database column but, as we said, unescaping is performed only by compiler and you get exactly what you stored.
If you can I'd suggest to simply store "البنك المتحد" in your database column.
If you can't change that and you ALREADY USE Apache Common Lang you can use an utility function to perform unescaping:
Of course I wouldn't suggest to use it only for this (it's all but small), if you need it check tchrist's answer in How to unescape a Java string literal in Java.