在 grails 中填充下拉列表
populate a dropdown in grails
我有一个用户,我给了它一个角色,我想在创建用户时,在下拉列表中显示角色,然后我可以 select 我想给的角色他,我该怎么办??请我真的需要帮助,因为我是 Grails 的新手,这里是 user.groovy
class User {
transient securiteService
String username
String password
String nom
String prenom
String email
String tel
static hasMany = [roles : Role]
static constraints = {
username blank: false, unique: true
password blank: false,display: false
nom nullable: true
prenom nullable: true
email email:true, nullable:true
tel nullable:true, maxSize:20, matches:/[\+]{0,1}[0-9\s]{3,15}/
}
static mapping = {
password column: '`password`'
sort nom: "asc"
affectations sort : "dateAffectation", order:"desc"
intervention sort : "responsable", order:"desc"
}
}
以下示例将帮助您根据需要对代码进行必要的更改。
例如你有一个 table / domain Role
class Role {
String roleId
String roleName // e.g ROLE_ADMIN
}
// 填充 GSP 视图中的下拉列表(这将填充角色 table 中存在的所有角色)
<g:select from="${Role.list().roleName}" name="selectUserRole"
optionKey=""
optionValue=""/>
我有一个用户,我给了它一个角色,我想在创建用户时,在下拉列表中显示角色,然后我可以 select 我想给的角色他,我该怎么办??请我真的需要帮助,因为我是 Grails 的新手,这里是 user.groovy
class User {
transient securiteService
String username
String password
String nom
String prenom
String email
String tel
static hasMany = [roles : Role]
static constraints = {
username blank: false, unique: true
password blank: false,display: false
nom nullable: true
prenom nullable: true
email email:true, nullable:true
tel nullable:true, maxSize:20, matches:/[\+]{0,1}[0-9\s]{3,15}/
}
static mapping = {
password column: '`password`'
sort nom: "asc"
affectations sort : "dateAffectation", order:"desc"
intervention sort : "responsable", order:"desc"
}
}
以下示例将帮助您根据需要对代码进行必要的更改。 例如你有一个 table / domain Role
class Role {
String roleId
String roleName // e.g ROLE_ADMIN
}
// 填充 GSP 视图中的下拉列表(这将填充角色 table 中存在的所有角色)
<g:select from="${Role.list().roleName}" name="selectUserRole"
optionKey=""
optionValue=""/>