Chris Lacy's Software Engineering Blog
Thursday Nov 26, 2009
Grails AJAJ Autocomplete
Currently only working with grails 1.2-M3 (grails-ui plugin fails in M4)
package net.chrislacy.grails
import grails.converters.JSON
import java.util.concurrent.ConcurrentSkipListSet
class AjajController {
static names = ['Blaire','Carol','Chris','Christy','Conan','Heather','Olivia'] as ConcurrentSkipListSet
def index = {[names:names]}
def autoCompleteMe = {
def query = params.query
def next = query + Character.MAX_VALUE
def foundNames = names.subSet(query, true, next, true).collect{[name:it]}
render([result:foundNames] as JSON)
}
def add = {render names << params.name}
}
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>AJAJ Example</title>
<gui:resources components="['autoComplete']"/>
<g:javascript library="prototype" />
</head>
<body>
<g:formRemote name="add" url="[controller:'ajaj', action:'add']" update="update">
<gui:autoComplete name="name" controller="ajaj" action="autoCompleteMe" minQueryLength="1" />
<g:submitButton style="display:none" name="add"/>
</g:formRemote>
<div id="update">${names}</div>
</body>
</html>
Posted at 08:56PM Nov 26, 2009 by chris in General |
Comments: