Dynamic filtering with jQuery and XML

February 3, 2010 Robert Shane Zehnder 2 comments

Back in November I wrote a short piece on dynamic search filtering using jQuery and using ajax.load() to populate a search div.  A reader asked if it was possible to do the same thing with an XML document and it is quite easy to do.  I do not have it searching over multiple nodes, but with a little array-fu I imagine it can be modified to handle it.

Also I will note I did get most of the code from learncf.com, and more specifically http://tutorial18.learncf.com by Scott Bennett.  I just wanted to make sure I gave credit where credit was due.

The search page is exactly the same as the previous post, we have just modified the query.cfm to use an XML document instead.  Here is our new query.cfm file:

<cfparam name="url.search" type="string" default="">
<cfsavecontent variable="books">
<?xml version="1.0"?>
<books>
 <book>
 <isbn>0321330110</isbn>
 <title>Macromedia ColdFusion MX 7 Certified Developer Study Guide</title>
 <author>Ben Forta</author>
 </book>
 <book>
 <isbn>0596004206</isbn>
 <title>Learning XML, Second Edition</title>
 <author>Erik Ray</author>
 </book>
 <book>
 <isbn>0782140297</isbn>
 <title>Coldfusion MX Developer's Handbook</title>
 <author>Raymond Camden</author>
 </book>
</books>
</cfsavecontent>

Search page
<cfset booksXml = XmlParse(books)/>

<cfset SearchByTitle = xmlSearch(booksXml,'//book [contains(title,"#url.search#")]')>
<cfoutput>
 #arrayLen(SearchByTitle)# Book(s) Found<br /><br />
 <cfloop from="1" to="#arraylen(SearchByTitle)#" index="i">
 <cfset BookXML = xmlparse(SearchByTitle[i])>
 <b>ISBN:</b> #BookXML.book.isbn.xmltext# - <b>Title:</b> #BookXML.book.title.xmlText# - <b>Author:</b> #BookXML.book.author.xmlText# <br />
 </cfloop>
</cfoutput>

I have used the hard-coded XML Scott used in his tutorial, but it could easily be modified to dynamically load the XML.   We are searching the Title nodes for each title that contains our search string and it is case-sensitive.   I might play around with this a little more later today and see if I can make it more robust.

I have a demo of this code here: http://www.kisdigital.com/tests/filter

Edit:

I did some research and found this post by Ben Nadel explaining the XmlSearch() function in detail.  Expanding the search field to other nodes in the XML document is very easy.  For instance, if you wanted to search on titles and authors you could modify the XmlSearch string as follows:

‘//book [(contains(title,"#url.search#")) or (contains(author,"#url.search#")) ]‘

I think Ben’s site covers just about everything.  ;)

Categories: ColdFusion, jQuery

A hectic few weeks

January 22, 2010 Robert Shane Zehnder 3 comments

After getting laid off from my full-time job last year, I spent the last few months of 2009 doing free-lance work whenever possible and just trying to make ends meet.  While it tends to be entertaining, it definitely does nothing to diminish my impressive collection of gray hair.  However, my Christmas present this year was a full-time ColdFusion development position in Greensboro, NC.  After a few rough months and a year of jumping from contract to contract that was probably the best gift I have ever received.

That being said, 2010 is off to a great start even if the first few weeks have been a little crazy.  Unfortunately my only laptop decided to burn itself up, but it was on its last leg so that wasn’t a huge surprise.  I am saving up for a new machine so I can get back to work on the personal and collaboration projects planned for this year.  I definitely intend to pick up some new frameworks and write a lot more jQuery.  If I learn something new, I will share with all of you.

I hope you all are having a great year as well.

Categories: General

Merry Christmas and Happy New Year!

My family and I would like to take a few moments before the season really kicks off to wish everyone one a Merry Christmas and Happy New Year!  It has definitely been an interesting year with all kinds of trials and tribulations, but I guess that just makes sure life is always interesting.  Overall I would say 2009 was a good year and 2010 looks like it is going to be off to a great start.

In closing, I hope everyone has a happy and safe holiday season.  I look forward to hearing from you all next year!

Categories: General

Updated WhosOnCFC 2.2.4 on RIAForge

I just uploaded a new zip package to RIAForge that has an updated version of WhosOnCFC 2.2.4 from the version uploaded yesterday.  I had an issue in Application.cfc that Todd Rafferty helped me run down and that has been corrected.  It also includes a newly updated version of the jQuery session viewer.  I tried to be thorough when I wrote the jQuery viewer so you could watch your sessions, but at the same time added in some nice jQuery UI elements as well.  Again, you can find the live demo here: http://www.kisdigital.com/tests/jView.

I have also changed the SVN hosting for WhosOnCFC.  I have been using git almost exclusively lately, so I have switched over to github for handling version control.  I usually push to github at the end of the day so if you are interested in having the most up-to-date version you can generally find it here: http://github.com/robertz/WhosOnCFC.

Categories: ColdFusion, Railo, WhosOnCFC

New viewer for WhosOnCFC

Last night I quickly threw together a new viewer for WhosOnCFC using jQuery.  The old enhanced viewer is nice, but I have been using open-sourced ColdFusion engines and most do not play nicely with the CFLayout tag.  Also it was a good diversion since I have been working on the same project for weeks now.

It is in the early stages and still needs a little work, but here is what I currently have.  Suggestions are welcome!

http://www.kisdigital.com/tests/jView/

Categories: ColdFusion, Railo, WhosOnCFC, jQuery

Colorbox and jQuery form plugin for attractive interfaces

November 30, 2009 Robert Shane Zehnder 1 comment

Lately it seems like it is becoming harder to program an effective user interface without the use of javascript.  I for one must admit I have drank the jQuery kool-aide.  I was working on a site for a client and needed a way for the users to change their password.  The site in question also makes extensive use of the Colorbox jQuery plugin and I know that Colorbox can display inline HTML so I thought this would be a good chance to check it out.  It will be aesthetically pleasing and it would be one less page I would have to write, I could just add the code to my current member page.

Read more…

Categories: ColdFusion, jQuery

Dynamic search filtering with jQuery

November 27, 2009 Robert Shane Zehnder 5 comments
Today I was working on a project for a client and they wanted a way to easily search through their 400 or so users.  I wanted a way to do it dynamically (ala project search on RIAForge) so I whipped up a quick little script that does just that.  Using jQuery made is surprisingly easy, but I figured I would share.

Read more…

Categories: ColdFusion, jQuery

Happy Thanksgiving!

I would just like to take a moment and wish everyone a happy Thanksgiving and I hope you all  have a wonderful and safe holiday.  Much like the elevator business, my life has had its ups and downs this year, but I still have much to be thankful for.  I have gained quite a few clients this year, both me and my family have been healthy, and I have some great friends I would not trade for the world.  I do not know what more I could ask for.

If you are on the other side of the pond, I hope you still have a happy and safe day, too. :)

Categories: General

Railo and Tomcat made easy

November 23, 2009 Robert Shane Zehnder 3 comments

I have seen several posts recently about installing Railo for local development, so I figured I would point out a nicely pre-configured Railo/Tomcat package out there from the folks at Vivio Technologies, which can be found here: http://railo.viviotech.net.  They have packages for both Windows and Linux, so you should have your bases (and operating systems) covered.   One other benefit of using the package is no web server is required.  Tomcat will act as its own web server.

It is very easy to install new webs using the package, the only thing required is editing your Tomcat server.xml file and add a new entry into the virtual hosts section.  A typical entry will look like this:

<Host name="site1.localhost" appBase="webapps">      
    <Context path="" docBase="C:\Sites\site1.localhost" />
</Host>

After you have made the appropriate changes to your HOSTS file and restart Tomcat you will be in business.

Categories: ColdFusion, Railo

Getting to know Transfer ORM

November 19, 2009 Robert Shane Zehnder 1 comment

I realize this post comes at an awkward time.  It seems most of the posts about ORMs nowadays all center around Hibernate after the release of ColdFusion 9.  However, if like me, you are using some of the open-sourced CFML engine alternatives like Railo or OpenBD, Hibernate support might be on the project road map but it is not here yet.  I still have quite a few sites out there running Transfer ORM, so I for one will be supporting it as long as it is available.

Read more…

Categories: ColdFusion, Transfer ORM