[ 22 posts ] Go to page 1, 2, 3 Next

Lisa

  • Username: lira
  • Joined: Wed Jun 02, 2010 10:48 pm
  • Posts: 7
  • Offline
  • Profile

XHRDataSource: Special characters

Post Posted: Mon Jun 07, 2010 3:51 am
+0-
Hi,
I´m not sure if this is a datasource question or not but here I go...
I use the autocomplete component with a XHRDataSource.
When the user types a special character like å, ä or ö the server doesn´t get them.
When I use a FunctionDataSource I do
Code:
decodeURI(query);
to get the characters.
What can I do to send the special characters to the server?
Thanks!
:-)Lisa

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: XHRDataSource: Special characters

Post Posted: Mon Jun 07, 2010 9:30 am
+0-
Characters beyond those that used to get punched on tape are encoded using different systems. It is a good idea to explictly state what encoding you want and make sure your server understands that same encoding or you can somehow do the conversion yourself. This encoding is different from the URI encoding necessary just to escape the special characters in a URL: ?&=+%/. None of these use any diacritical marks. The best is if you can encode your page using UTF-8, it takes all characters and is supported more or less Ok across all platforms. If you have one of the ISO-xxxx, it might not always work. You can see your message with all those characters in this page, look at the source, it uses UTF-8.

Lisa

  • Username: lira
  • Joined: Wed Jun 02, 2010 10:48 pm
  • Posts: 7
  • Offline
  • Profile

Re: XHRDataSource: Special characters

Post Posted: Sun Jun 13, 2010 10:21 pm
+0-
Thanks for your reply, Satyam! :-) Sorry for my late reply!

In my jsp-page I have set the content-type to:
<meta http-equiv="content-Type" content="text/html; charset=utf-8"/>

When the query-string from the auto-complete field arrives at the server I get:
lö
making the database-query return nothing.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: XHRDataSource: Special characters

Post Posted: Sun Jun 13, 2010 11:33 pm
+0-
I'm sorry I cannot help any further. I faced the same problem and started playing with settings until I got it right and now I can't even tell you how I got there. My server is not jsp either so I can't advise on yours. If you are using the Firebug debugger in Firefox, I would go to the Net tab and check the request headers and see if it is sending the character encoding header and, if not or wrong, I would set it to confirm that it is utf-8 since I don't know what jsp would assume if no such header is present.

Can someone with knowledge in JSP help?

QmunkE

  • Username: QmunkE
  • Joined: Thu Feb 19, 2009 1:57 pm
  • Posts: 15
  • Offline
  • Profile

Re: XHRDataSource: Special characters

Post Posted: Mon Jun 14, 2010 2:12 am
+0-
Make sure that the JSP also has this declaration at the top:

Code:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>


and maybe use firebug to check the actual request parameters to make sure they're being sent correctly?

Lisa

  • Username: lira
  • Joined: Wed Jun 02, 2010 10:48 pm
  • Posts: 7
  • Offline
  • Profile

Re: XHRDataSource: Special characters

Post Posted: Mon Jun 14, 2010 9:32 pm
+0-
Thanks for your replies!!!

I checked the headers in Firebug and it said:
Content-Type text/html;charset=ISO-8859-1

I will try the page declaration and see how that works out.

Lisa

  • Username: lira
  • Joined: Wed Jun 02, 2010 10:48 pm
  • Posts: 7
  • Offline
  • Profile

Re: XHRDataSource: Special characters

Post Posted: Mon Jun 14, 2010 9:45 pm
+1-
I tried the page declaration and when the whole page are loaded then the content type header is set to:
Content-Type text/html;charset=UTF-8

But when I use the autocomplete field the type header is:
Content-Type text/html;charset=ISO-8859-1

Can you somehow specify the charset the datasource should use?

Larry Kluger

  • Username: larryk
  • Joined: Sat Jul 04, 2009 7:36 pm
  • Posts: 37
  • Offline
  • Profile

Re: XHRDataSource: Special characters

Post Posted: Tue Jun 15, 2010 11:07 am
+0-
I think your problem is that the default YAHOO.util.Connect.asyncRequest character set is not specified. Then you tend to get the iso-8859 setting which is not what you want.

Fix: use your own function for Yahoo asyncRequest instead of the default. From my codebase:
Code:
YAHOO.ma.asyncRequest = function(method, uri, callback, postData) {
  // Same as YAHOO.util.Connect.asyncRequest but sets character set to UTF-8
  // See http://tech.groups.yahoo.com/group/ydn-javascript/message/16848
  var connect = YAHOO.util.Connect;
  connect.initHeader('Content-Type', 'text/html; charset=UTF-8', true);
  connect.initHeader('X-Requested-With', 'XMLHttpRequest', true);
  connect.setDefaultPostHeader(false);
  if (method == 'POST' && postData == null) {
     postData = ' '; // needed in order to get a content-length header
  }
  return connect.asyncRequest(method, uri, callback, postData); 
};

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: XHRDataSource: Special characters

Post Posted: Tue Jun 15, 2010 11:52 am
+0-
Indeed,the default headers say nothing about encoding. An alternative, though is that the connMgr property of the XDRDataSource gives you access to the Connection Manager that it will use so you can set the headers on that one, instead of handling the remote connection all by yourself. You could do:

var connect = myDataSource.connMgr;

and then do the header settings as you show.

On the other hand, it should be possible to tell the server what encoding to assume if none is specified, I can't believe that those .jsp pages cannot handle anything but ISO-8859 without explicit help from the client telling it otherwise.

Larry Kluger

  • Username: larryk
  • Joined: Sat Jul 04, 2009 7:36 pm
  • Posts: 37
  • Offline
  • Profile

Re: XHRDataSource: Special characters

Post Posted: Tue Jun 15, 2010 12:05 pm
+0-
@Satyam, thanks for the pointer on how to set the headers.

Re whether they should be set or not: the default assumption is for the initiator (the client) is to tell the server the character set that the client will be using. Otherwise you're depending on defaults.

So, while it is possible to futz with the server to tell it that the default character set should be utf-8 instead of 8859, I think the cleaner approach is for the client to correctly tell the server what char set it is using.

The underlying problem is that the 'web-standard' for Western European/US used to be 8859. The good news is that now the standard is UTF-8 which covers far more countries. But a lot of sw and frameworks were and are defined to use 8859 as a default.

Bottom line is that it is no longer appropriate to depend upon the default char set as being "right" -- that's a sure plan for failure.

Instead, specify utf-8 everywhere, including in your db connections and table definitions.

All examples for the XDRDataSource (and client widgets) should include setting the char set to utf-8.
  [ 22 posts ] Go to page 1, 2, 3 Next
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum