填写grails中的下拉列表

时间:2018-05-09 09:49:51

标签: grails dropdown

我有一个用户,我给它一个角色,我想当我创建用户,在下拉列表中显示角色,然后我可以选择我想给他​​的角色,我该怎么办?它?请我真的需要帮助,因为这里的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"
}
}

1 个答案:

答案 0 :(得分:0)

以下示例将帮助您根据需要对代码进行必要的更改。 例如,您有一个表/域角色

class Role {
   String roleId
   String roleName  // e.g ROLE_ADMIN
}

//填充GSP视图中的下拉列表(这将填充Role表中的所有角色)

<g:select from="${Role.list().roleName}" name="selectUserRole"
                                optionKey=""
                                optionValue=""/>
相关问题