Skip to main content

Yahoo autocomplete and service - doesnt parse data?

8 replies [Last post]
ethnoe
Offline
Joined: 2008-11-09
Points: 0

This is my first post on this forum - hello everyone! :)

Getting staright to the problem - i am using yahoo Autocomplete widget in my project. Naturally i want it to be populated with data from database. Unfortunatelly it seems Autocomplete can't parse data i'm sending.

Widget instantiation:

categoryAutocomplete is a servlet which takes care of getting data from database and then returns model to jsp page:

<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

[

{ label: "${item.value.name}", value: "${item.key}" },

{ label: "always_here", value: "0" }
]

When i use firebug to see the response sent by servlet to autocomplete i see a proper JSON code:
[
{ label: "first", value: "1" },
{ label: "always_here", value: "0" }
]

When i copy&paste it as a value="" attribute of widget everything works just fine. But when using service autocomplete is not populated, cant see any errors in firebug consoles.. what have i done wrong? I have been searching the internet for any info or documentation, but there is almost none.

Message was edited by: ethnoe

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
maltec_23
Offline
Joined: 2009-02-06
Points: 0

I am using yahoo.autocompleter as
. I am able to fetch data using the it.

But,
On submitting the form.. the parameter is not listed under request parameters.. in simple words it doesn't pass to my servlet.

Any Suggestions?

gmurray71
Offline
Joined: 2003-07-31
Points: 0

Hi Ethnoe,

Sorry about the trouble. There was a bug with the service processing on the yahoo autocompleter which I have now fixed.

You can find the latest yahoo 1.8.1 widgets at:

http://jmaki.com/downloads/widgets/

or you can just replace the individual /resources/yahoo/autocomplete/component.js with;

https://widgets.dev.java.net/source/browse/*checkout*/widgets/trunk/code...

Let me know if you still have problems with it.

Regards,

-Greg

ethnoe
Offline
Joined: 2008-11-09
Points: 0

Hello Greg!

I just tried replacing the code of component.js, as i don't want to mess with whole yahoo widgets (done some custom changes to these resources) unless it's necessary. Unfortunately there are some complications.

The problem with parsing data has been solved - static data included in .jsp shows up.

New problem is:
With the old component.js when typing in autocomplete box i can see the requests to my servlet are sent. With new component.js there is only one request sent when widget is instantiated, without query parameter, but then when typing there is no communication with the service servlet. So static data included in .jsp shows up, but the widget is not being refreshed while typing.

I tried to compare old and new component.js files, but i know jmaki too little to be able to come up with some solution by myself.

I uploaded the old component.js file here: http://home.elka.pw.edu.pl/~adubiel/jmaki/

I will appreciate any further tips :)

gmurray71
Offline
Joined: 2003-07-31
Points: 0

Hi,

So I changed the component so it will do server queries for the data.

There are updates you will need to do:

1) in your component you will need to add an argument : completionMethod : server:

Example:

args="{completionMethod : 'server'}"
service="test.jsp" />

2) Because of a limitation I can't seem to get around with the yahoo data sources processing of xmlhttprequest based arrays we need to have an object instead of an array returned:

The format is :

{ items : [
{label : 'Alabama', value : 'AL'},
{label : 'Alabama 2', value : 'AL 2'},
{label : 'Alabama 3', value : 'AL 2'},
{label : 'California', value : 'CA'},
{label : 'New York', value : 'NY', selected : true},
{label : 'Texas', value : 'TX'}
]
}

Basically you need an object wrapper with an items property for the array.

Limitations :

Currently when using server based completion we are not able to associate jMaki actions on the items the server completionMethod. Also the onSelect events aren't being fired.

All said if you can live with the limitations for now (I'm going to see if I can work around them). Then give the code in the workspace another run.

https://widgets.dev.java.net/source/browse/*checkout*/widgets/trunk/code...

-Greg

ethnoe
Offline
Joined: 2008-11-09
Points: 0

Testing updated file brought one serious problem.
I changed the widget args, also the data format. But when i add completionMethod argument, i get following error at the instantiation:

YAHOO.util.XHRDataSource is not a constructor
it points at line 148 of component.js file:
ds = new YAHOO.util.XHRDataSource(wargs.service);

Without completionMethod widget setups okay, but there is no communication with servlet.

I will use some other autocomplete widget, but i'm still eager to help solving this bug.

gmurray71
Offline
Joined: 2003-07-31
Points: 0

hi,

If this is the case you are going to need to upgrade the dependencies along with the widget. Yahoo upgraded some of their APIs with their last release and I bet you are working with a slightly older version. Could you follow the following steps and upgrade your Yahoo widgets?

1) Back up your app in case bad things happen

2) Download the latest yahoo widget library from : http://jmaki.com/downloads/widgets/ (I just updated it)

3) Install upgrade the yahoo library. If you are in netbeans see: http://weblogs.java.net/blog/ludo/archive/2007/01/extending_the_j.html, eclipse use the add widgets button. If you are not using a tool simply unzip the contents and copy the resources into the resources directory of your web application.

4) remove / rename the /resources/yahoo/autcomplete from your application. If you have other yahoo widgets I would just remove the one. Even if you have other yahoo widgets in the app their dependencies won't be effected because we namespace the different version of yahoo libraries using different directory names.

5) If you are using /netbeans / eclipse simply drag the widget into page again to get the resources to be copied in your web application.

Can you give the steps above a try and let me know what happens? This might seem like a lot but it should be real easy to try.

Regards,

-Greg

ethnoe
Offline
Joined: 2008-11-09
Points: 0

Well, i updated jMaki resources month ago for the last time. Now i know it is an important factor when struggling with bugs.

After update everything is working flawlessly. Thanks for helping me out, Greg!

gmurray71
Offline
Joined: 2003-07-31
Points: 0

Hi Ethnoe,

We tried to design jmaki in tiers where the runtimes and the widget libraries can be upgraded with different frequency. We do make an effort to make sure the code you write to interact with your widgets shouldn't need to change.

With Yahoo's latest upgrade to 2.6 their APIs did change and we have done pretty good about shielding our users from the change but you would need their latest libraries as well and that is what the full widget update which included that as well.

I'm glad to see you up and running.

-Greg