Generic search dialog causes Java compilation errors
The following generic definition of a search dialog is accepted by the WebDSL compiler, but generates Java code that is not compilable.
function entityList(persons: List): List {
//return [p as Entity | p: Person in persons];
var xs := List();
for(p: Person in persons) { xs.add(p as Entity); }
return xs;
}function searchEntity(entity: Entity, query: String, limit: Int): List {
if(entity is a Person) {
return entityList(searchPerson(query, limit));
}
return null;
}define searchEntity(entity: Entity) {
var tname := getTemplate().getUniqueId()
var name : String
action updateSearch(n : String) {
log(“updateSearch(” + n + “)”);
replace(“entitySelection” + tname, searchEntity(entity, n));
}
form[class = “form-search”] {
input(name)[onkeyup = updateSearch(name)]
placeholder “entitySelection” + tname { }
}
}define ajax searchEntity(entity: Entity, name : String) {
Submitted by Eelco Visser on 22 April 2012 at 14:01
var candidates : List := searchEntity(entity, name + “*”, 10)
if(candidates.length > 0) {
div[class=“dropdown open”]{
dropdownMenu{
for(p : Entity in candidates) {
dropdownMenuItem{ render(p) }
}
}
}
}
}
Log in to post comments