Hello All, 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?
Thank you for your time!
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);
}
@Override
public Widget asWidget()
{
VerticalPanel container = new VerticalPanel();
SimplePanel panel1 = new SimplePanel();
panel1.getElement().setInnerHTML(TEXT1);
container.add(panel1);
SimplePanel panel2 = new SimplePanel();
panel2.getElement().setInnerHTML(TEXT2);
container.add(panel2);
return container;
}
}
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;
}
}
*Note: in case my unicode characters got stripped from this post
(TEXT2/content2.html contains the same string with the raw unicode
characters).*
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/_WZhvalE9tgJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.
<<attachment: UnicodeTest1.png>>
<<attachment: UnicodeTest2.png>>
