Part 3 of GrailsUI Screencast Series: Advanced AutoComplete

The 3rd installation of my GrailsUI Screencast series deals with some more advanced usage of the AutoComplete component. It starts off where the previous AutoComplete screencast leaves off.

Music is “Rusty Cage” by Soundgarden.

So far, the series goes like this:

  1. Part 1: GrailsUI Basics (expandablePanel, accordion, tabView)
  2. Part 2: GrailsUI AutoComplete Basics
  3. Part 3: GrailsUI Advanced AutoComplete
  4. Part 4: GrailsUI DataTable (COMING SOON)
This entry was posted in grails plugins and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

35 Comments

  1. Yorchs
    Posted April 17, 2009 at 11:55 am | Permalink

    Excellent screencast! Congratulations!
    I would like to ask you a question:
    Is it possible to use the autocomplete component with grails as a multitag input like the one you can find in del.icio.us for example?
    Thanks in advance.

  2. Posted April 17, 2009 at 12:42 pm | Permalink

    If you are a registered member of Grails.org, within the plugin portal you can do multitags within one autoComplete. To see this working, just login to grails.org (you may have to register), then go to any plugin in the Plugin Portal and click the little green “+” icon to add new tags. This will pop up an autoComplete in a dialog where you can start typing tag names.

    You’ll notice that once you have chosen one tag and typed a comma, the autoComplete server logic is smart enough to provide you with a list that includes your already-typed tags.

    If you take a look at the TagController starting at around line 107, you’ll see how I did this on the server.

  3. Yorchs
    Posted April 20, 2009 at 3:44 am | Permalink

    Great! This is just what I was looking for.
    Thanks a lot from Spain.

  4. Daniel Serodio
    Posted April 20, 2009 at 11:00 pm | Permalink

    Where can I download the source code? Apperently, http://tinyurl.com/gui-sc3-start doesn’t work…

  5. Posted April 21, 2009 at 8:17 am | Permalink

    Hey Daniel, sorry about that! I just uploaded the source, so the link should work now.

  6. Bálint Kozman
    Posted April 22, 2009 at 9:39 am | Permalink

    Excellent screencast (just like the previous one)!
    Thanks for it.

    Btw, what tool did you use to shoot the screen?

  7. Posted April 22, 2009 at 9:42 am | Permalink

    Thanks, Bálint. I use ScreenFlow for my screencasting. I like it quite a bit.

  8. Posted April 22, 2009 at 2:37 pm | Permalink

    Hey Matthew! Since at least yesterday, I can’t install GrailsUI anymore.
    When I do “grails install-plugin grails-ui” it fails upon extraction of “yui 2.7.0″.
    I believe the download URL points to a bad location. Or am I doing something wrong?

  9. Posted April 22, 2009 at 3:04 pm | Permalink

    Quick follow-up: there is a workaround as described here:
    http://www.pubbs.net/grails/200904/40990/

  10. Posted April 22, 2009 at 7:06 pm | Permalink

    Thanks Felix. The problem is with the latest release of the YUI plugin, because the new YUI 2.7.0 source is not in the same place as the last release (sourceforge). Marcel will be fixing it soon. In the meantime, you can bypass this issue by manually installing the YUI plugin version 2.6.1 like this:

    grails install-plugin yui 2.6.1

  11. Rawi
    Posted May 3, 2009 at 10:41 am | Permalink

    Both GrailsUI and Screencasts are excellent works! Thank you 4all!

    Could you elaborate more on two-way dependencies between 2 autoComplete fields and on multiple dependencies on other autoCompletes?
    All my attemptes were in vain. That’s throughly real world scenario…
    Do you have some hints on it?
    Thanks again!

  12. Thomas
    Posted May 3, 2009 at 5:03 pm | Permalink

    Hi Mat,

    I’m new to grails.
    These screencasts are great. Thank you for your work.

    Thomas

  13. Posted May 3, 2009 at 8:15 pm | Permalink

    @Rawl, I’m sure I could help you out if you gave me a sample of the code you’re attempting. It would be a very good idea to register for the grails-user mailing list and ask your questions there. I monitor those lists for questions about GrailsUI.

  14. uday
    Posted May 19, 2009 at 3:59 am | Permalink

    Hi,
    Could you tell me how i could change the color of ONE tab in the tabView, i went to the tabView-skin.css and tried a few things but was unsuccessful.

    may be a few pointers would go a long way..

    thank you,
    -U

  15. Posted May 19, 2009 at 6:26 am | Permalink

    @uday, you can give your tabs a class that contains the color you want by passing class=’whatever’. You can see an example here.

  16. Posted May 21, 2009 at 8:27 pm | Permalink

    Just a comment about your dynamic method by interpolating the params, surely there could be a security vulnerability to that practice? It seems as though arbitrary params coming from the request are used to form a method call. Is there some measure taken to ensure the containment of that data?

  17. Posted May 21, 2009 at 9:22 pm | Permalink

    @Chris In a real-world application, these methods would be secured by something like the acegi or jsecurity plugins, which would ensure that they cannot be accessed unless a valid user is logged in. I understand your concern about the security of using the request params in any case for calling a method dynamically, so if you think there are attributes of the domain object in question that you wouldn’t want users to see, I would suggest that this be restricted in the controller that serves the autocomplete call. This would definitely be a problem if Person.findBySsnLike(’%') happened to be called.

    In short, you are correct that this could be a security issue. It would be the programmer’s responsibility to ensure no sensitive attributes be revealed.

  18. Josh
    Posted October 7, 2009 at 10:40 am | Permalink

    Is it possible to use the current implementation of AutoComplete with DataTable… Any tips? I see an example with the yui plugin http://developer.yahoo.com/yui/examples/datatable/dt_autocomplete.html but can’t figure out how to implement with GUI.

    Thanks

    Josh

  19. Posted October 7, 2009 at 11:22 am | Permalink

    Yes, it is possible. You would need to create the autoComplete and attach an itemSelectEvent handler to it that would call the dataTable’s addFilter method. Something like this (off top of head):

    GRAILSUI.myAutoComplete.itemSelectEvent.subscribe(function(type, args) {
        var filterValue = args[2].value; // args[2] is the object literal of the selected item
        GRAILSUI.myDataTable.addFilter('some name', filterValue);
    });
    

    You would need to properly handle this new request on the server side as well, as you’ll get new “filter” and “filterBy” params.

  20. Josh
    Posted October 7, 2009 at 1:45 pm | Permalink

    I appreciate the quick response. I wish I could attend your sessions at SpringOne / 2GX because I have a feeling they’ll cover the basics of this.

    I’m not sure how to “attach an itemSelectEvent handler to it.” More specifically where would that bit of code you provided go? In the gsp, or do I need to go add it to the InputTagLib.goovy?

    Is “myAutoComplete” and “myDataTable” referring to the id’s of the autoComplete and dataTable?

    Thanks again

    Josh

  21. Josh
    Posted October 7, 2009 at 2:00 pm | Permalink

    Also I did read your \Learn Java Script!\ rant, and that’s why I’m trying to do this stuff! :-D

  22. Posted October 7, 2009 at 2:13 pm | Permalink

    @Josh You would put that code in your GSP in a script tag. And you’d need to wrap it in the YAHOO.util.Event.onDOMReady method after the grailsUI tags in order for it to have access to the components it needs. And yes, those are referring to the ids of the tags.

  23. Josh
    Posted October 7, 2009 at 3:51 pm | Permalink

    Thanks! It’s working..

    Here’s what I ended up having in my gsp:

    YAHOO.util.Event.onDOMReady(function() {

    GRAILSUI.myAutoComplete.itemSelectEvent.subscribe(function(type, args) {
    var filterValue = args[2][1]; // args[2][1] is the id of the autoComplete
    GRAILSUI.myDataTable.addFilter(’id’, filterValue);
    });

    });

    The ‘id’ and filterValues are then just passed in as “filterBy” and “filterOn” params.

    Josh

  24. Posted October 7, 2009 at 3:54 pm | Permalink

    Great! And if you want to clear the filter, call GRAILSUI.myDataTable.clearFilters() or .clearFilter(’name’).

  25. Posted November 3, 2009 at 12:36 pm | Permalink

    great screencasts there Matt! waiting for part 4 (and also something on Drag n Drop) . is this supported by GrailsUI btw?

  26. Posted November 4, 2009 at 8:55 am | Permalink

    @rawkafella I am not sure when I’ll get around to the next screencast, but it will be on the DataTable if I do it at all.

    And yes, there is a drag and drop GrailsUI component. See http://grails.org/plugin/grails-ui for details.

  27. Posted November 5, 2009 at 2:25 am | Permalink

    @Matt yeah i could get its gonna be DataTable which is cool. DragNDrop just adds a “whoa!” factor and for a larger audience. maybe u wud wanna do that sometime in future (great that its supported!)

    last but not the least - UNREAL RAD there! i’m super impressed. hopefully u’ll keep adding to it.

  28. Chris
    Posted November 12, 2009 at 9:59 am | Permalink

    Nice! .. was looking for this. Great plugin! :)

    Matthew - would you happen to know some resource which has implemented Drag N Drop while maintaining the state of components. (ie. their position, expand-collapse etc.) some thing like the widgets in iGoogle? Or any suggestions?

    Would that kind of a thing (generating ajax calls to backend to save states) be possible with Gui?

  29. Chris
    Posted November 12, 2009 at 12:25 pm | Permalink

    hey!.. just did a quick test of DND. works good with simple lists. but when i add an expandablePanel nothing shows up.
    something like -

    ….

    Please tell me this sorta thing will work! :D

  30. Posted November 12, 2009 at 12:28 pm | Permalink

    Hi Chris. At the moment, the DND component only works with very simple elements. Sorry, but I don’t have plans to improve it in the future. Drag-and-Drop is a complex and very customized thing, and you would have better luck getting to know the YUI underpinnings of it or use the jQueryUI “selectable”, “draggable”, “droppable”, etc. stuff.

  31. Chris
    Posted November 12, 2009 at 12:52 pm | Permalink

    Might I also add that newlines inside LI do not work. If I add all the code in same line the component works (even then not for expandablePanel) but if I indent the code .. have multiple lines. Bam! No display.

    Sorry I’m adding all this here .. will create a JIRA account and log it there asap.

  32. Posted November 13, 2009 at 4:25 am | Permalink

    hello. is there a possibility to “disable” the collapse/expand function from expandablePanel.. ie. make it readonly. remove (+/-)
    I checked YUI lib to look for config pass-through but didnt have any luck.

  33. Posted November 13, 2009 at 7:46 am | Permalink

    I think persistent=”true”.

  34. Posted November 15, 2009 at 4:21 am | Permalink

    i did try that earlier on. persistent doesnt work. but thanks anyway :)

  35. Posted November 15, 2009 at 8:59 am | Permalink

    Ah, I guess that only works on the accordion.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*
Check out the latest GroovyMag to see an interview with me about the 1.1 release of GrailsUI: