I am having an issue with Unicode characters being displayed in dynamic text content.
Please consider the examples UnicodeTest1 and UnicodeTest2, bellow. I can get the desired behavior if I assign the content manually using the javascript escape codes for the unicode character (see UnicodeTest1). However, when I load the text with a RequestBuilder, I can't get any unicode characters to display, regardless of how that content is formatted (see UnicodeTest2).
What is the correct way to display unicode characters in text that was loaded from a RequestBuilder?
public class UnicodeTest1 implements EntryPoint, IsWidget
private static final String TEXT1 = "\u201CHello World!\u201D";
private static final String TEXT2 = "“Hello World!”";
public void onModuleLoad()
RootPanel.get().add(this);
VerticalPanel container = new VerticalPanel();
SimplePanel panel1 = new SimplePanel();
panel1.getElement().setInnerHTML(TEXT1);
SimplePanel panel2 = new SimplePanel();
panel2.getElement().setInnerHTML(TEXT2);
public class UnicodeTest2 implements EntryPoint, IsWidget
{
public void onModuleLoad()
{
RootPanel.get().add(this);
}
@Override
public Widget asWidget()
{
VerticalPanel container = new VerticalPanel();
final SimplePanel panel1 = new SimplePanel();
container.add(panel1);
RequestBuilder rb = null;
// Contains: \u201CHello World!\u201D
rb = new RequestBuilder(RequestBuilder.GET, "text1.htm");
try
{
rb.sendRequest(null, new RequestCallback()
{
public void onError(Request request, Throwable exception)
{
}
public void onResponseReceived(Request request, Response response)
{
GWT.log("Response: " + response.getText());
panel1.getElement().setInnerHTML(response.getText());
}
});
}
catch (RequestException e)
{
}
final SimplePanel panel2 = new SimplePanel();
container.add(panel2);
// Contains: “Hello World!”
rb = new RequestBuilder(RequestBuilder.GET, "text2.htm");
try
{
rb.sendRequest(null, new RequestCallback()
{
public void onError(Request request, Throwable exception)
{
}
public void onResponseReceived(Request request, Response response)
{
GWT.log("Response: " + response.getText());
panel2.getElement().setInnerHTML(response.getText());
}
});
}
catch (RequestException e)
{
}
return container;
}
}