String queryString = request.getParameter("term");
String searchProperty = getSearchProperty(request.getUser(), pc);
if (searchProperty == null) {
return new SimpleHttpResponse("Unsupported class " + model + "|").setMimeType("text/plain");
}
Manager<Object> manager = managers.forClass(pc.getMappedClass());
QuerySet<Object> qs = manager.filter(searchProperty + "__ilike", queryString + "%" )
.limit(0,500);
StringBuilder b = new StringBuilder("[");
char comma = ' ';
for (Object o : qs) {
b.append(String.format("%s{ \"id\": \"%s\", \"label\": \"%s\", \"value\": \"%s\"}", comma, manager.getPk(o), o.toString(), o.toString()));
comma = ',';
}
b.append("]");
return new SimpleHttpResponse(b.toString()).setMimeType("application/json");
}