|
| Web News |
Melodrama Over France Telecom The market reacted dramatically to the news that the French government will sell up to a 7.0% stake in France Telecom to fund tax cuts at home. But the news--while it grabbed headlines--will have little, if any, effect on the running of the telecom company. France Telecom...
French court slaps poor man's YouTube France's answer to YouTube has been found guilty of copyright infringement. As the Google-owned YouTube faces a U.S. lawsuit from movie and TV behemoth Viacom, a French high court has ruled against the...
France Télévisions, Orange sign exclusive... FranceTélévisions and Orange have signed an exclusive partnership to offer Orange customers a new service to view France Télévisions Group channel programmes on any screen (TV, PC, Mobile), at any time. The service, developed by Orange, is called 'Rewind TV', and is...
Orange makes nine-country deal to boost... Mobile-phone operator Orange is expecting the iPhone to raise awareness of its mobile-music services -- but it's working with Sony Ericsson to market its music portal in nine European countries. Speculation is rife as to which mobile operators will clinch deals to distribute...
HP in talks to buy Bull of France The US computer giant Hewlett-Packard is in talks to buy the French group Bull for 720 million euros (988 million dollars), the magazine Capital said on its Internet site Thursday. It said the two groups were in "advanced" talks, with HP expected to put forward a proposal in early...
Telecom Italia studying launch of mobile service... Telecom Italia SpA CEO Riccardo Ruggiero said that the group is studying the launch by the end of this year of a mobile phone service in France. 'We will come out with something this year,' Ruggiero said during a conference call, when asked if the company plans to use the...
Lycos, Kewego launch JubiiTV in Europe Internet company Lycos is partnering with Kewego for the launch of its online video service, JubiiTV, in Europe. Originally founded in France, Kewego provides white label video platforms to brands across Europe including...
|
 |
|
07.26.07 Coldfusion: AutoSuggest Example By
Raymond Camden
I've added autusuggest to ColdFusionBloggers.org and thought I'd talk a bit about how I did it (and about the problems I ran into).
First off - using autosuggest is extremely simple. All you have to do is take a standard input tag and switch it to a cfinput tag instead. Then just add the autosuggest attribute and your done. Thats it. Well, ok, you have to hook up the autusuggest to either a static list of suggestions, or to a dynamic data source.
For ColdFusionBloggers.org I decided the autusuggest would be based on previous searches. I added a logSearch() method to my entries CFC. This logged the search term and the time. I then added a method to return results based on what you type in the search box:
<cffunction name="getSearchHelp" access="remote" returnType="array" output="false">
<cfargument name="term" type="string" required="true">
<cfquery name="q" datasource="#variables.dsn#">
select distinct searchterm
from search_log
where searchterm like <cfqueryparam cfsqltype="cf_sql_varchar" value="#left(arguments.term,255)#%">
limit 0,10
</cfquery>
<cfreturn listToArray(valueList(q.searchTerm))>
</cffunction>
Notice I used #term#% for my search, not %#term#%. Why? Remember that autusuggest is based on what you type. If you type "R", you should see suggestions that start with R.
Then I ran into my first problem. Notice the datasource is variables.dsn. My Application.cfc file had created and initialized an instance of entries.cfc. Guess what happened when I hooked up ColdFusion directly to the CFC? Because I was accessing the CFC directly, variables.dsn wasn't set properly. I fixed it by changing to application.dsn, which worked, but I wanted a nicer solution.
| Learn How We Increased Conversion By 816% and Become A Certified Online Testing Professional™ Click Here |
|
The cool thing about binds in ColdFusion 8 is that you can link to CFCs, JavaScript functions, and random URLs. So my cfinput which had been using a CFC:
<cfinput name="search_query" autosuggest="cfc:components.entries.getSearchHelp
({cfautosuggestvalue})" maxResultsDisplay="10">
Was switched to this version:
<cfinput name="search_query" autosuggest="url:searchhelpproxy.cfm?term={cfautosuggestvalue}" maxResultsDisplay="10" showAutoSuggestLoadingIcon="false" size="10" />
I then added searchhelpproxy.cfm:
<cfif structKeyExists(url, "term") and len(trim(url.term))>
<cfinvoke component="#application.entries#" method="getSearchHelp" term="#url.term#" returnVariable="result">
<cfoutput>#serializeJSON(result)#</cfoutput><cfabort>
</cfif>
This file simply invokes the method I built but uses the Application scoped CFC instead. Notice that I have to format the result into JSON. Also note that Ben has blogged about some nice modifications made to autosuggest and cfselect bound controls.
If I have to do this again, I'll most likely create a more generic file that can handle different operations.
One last issue. I noticed that when I used the autusuggest control, it broke my layout a bit. I've pinged Adobe about this, but for now I've tried to make it work better by adding some style to my cfinput. In general I do not see a good reason why this should have any impact on layout, but maybe I did something wrong.
I've updated the code base again. You can download it on the FAQ at the site.
Comments
About the Author: Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com
Raymond Camden is Vice President of Technology for roundpeg, Inc. A long
time ColdFusion user, Raymond has worked on numerous ColdFusion books
and is the creator of many of the most popular ColdFusion community web
sites. He is an Adobe Community Expert, user group manager, and the
proud father of three little bundles of joy.
|
|