Select
select(x from y) can be used as input for an entity variable or for a collection of entities variable, where x is the variable or fieldaccess and y is the collection of options. It will create a dropdown box/select or a multi-select respectively. The name property of an entity is used to describe the entity in a select, see name property.
input(x) for an entity reference property or a collection property is the same as select, with as options all entities of its type that are in the database.
Example:
entity User {
username :: String (name)
teammate -> User
group -> Set<Group>
}
entity Group {
groupname :: String (name)
}
init{ //application init
var u := User { username := "Alice" };
u.save();
u := User { username := "Bob"};
u.save();
var g := Group { groupname := "group 1" };
g.save();
g := Group { groupname := "group 2" };
g.save();
}
define page root(){
form{
table{
for(u:User){
output(u.username)
input(u.teammate)
input(u.group)
}
}
submit("save",action{})
}
}
input(u.teammate) is a dropdown/select with options null, "Alice", "Bob". input(u.group) is a multi-select with options "group 1" and "group 2".
Example 2:
define page root(){
var teammates := from User
var groups := from Group
form{
table{
for(u:User){
output(u.username)
select(u.teammate from teammates)
select(u.group from groups)
}
}
submit("save",action{})
}
}
Equivalent to the previous example, but using explicit selects instead.
Example 3:
var u3 := User { username:="Dave" }
var g3 := Group { groupname:="group 3" }
define page root(){
var teammates := [u3]
var groups := {g3}
form{
table{
for(u:User){
output(u.username)
select(u.teammate from teammates)
select(u.group from groups)
}
}
submit("save",action{})
}
}
Options are restricted in this example, null and "Dave" for select(u.teammate from teammates) and only "group 3" for select(u.group from groups)
null
The null option for a select can be removed either by a not null annotation on the property:
teammate -> User (not null)
Or by setting [not null] on the input or select itself:
input(u.teammate)[not null]
select(u.teammate from teammates)[not null]
allowed
The possible options can also be determined using an annotation on the property:
group -> Set<Group> (allowed = {g3})
In this case just using input(u.group) will only show "group 3"
