【问题标题】:Grails Scaffold hide table columnGrails Scaffold 隐藏表格列
【发布时间】:2014-12-03 07:01:32
【问题描述】:

如何从 GORM 视图中隐藏 password 列:

我的域类:

class SecUser {
    static scaffold = true

    transient springSecurityService

    String username
    String password


    boolean enabled = true
    boolean accountExpired
    boolean accountLocked
    boolean passwordExpired



    static transients = ['springSecurityService']

    static constraints = {

        username blank: false, unique: true
        password (display:false, blank: false)



    }

    static mapping = {
        password column: '`password`'
    }

    Set<SecRole> getAuthorities() {
        SecUserSecRole.findAllBySecUser(this).collect { it.secRole } as Set
    }

    def beforeInsert() {
        encodePassword()
    }

    def beforeUpdate() {
    if (isDirty('password')) {
            encodePassword()
        }
 }

    protected void encodePassword() {
        password = springSecurityService.encodePassword(password)
        // password = password
    }
}

【问题讨论】:

  • 为什么在域类中有static scaffold = true
  • 这是一个例子。如果我删除它,它并不能解决我的问题
  • 我不希望删除它会解决问题。通常,该属性在域类中是没有意义的,除非您的应用程序(或您的应用程序正在使用的插件)中有代码对该属性执行某些操作。我认为默认的脚手架插件可以识别控制器中的该属性。

标签: grails hide scaffold


【解决方案1】:

display: false 约束用于从默认的脚手架视图中隐藏属性。 https://github.com/jeffbrown/scaffolddisplay 的项目证明了这一点。您的应用程序中必须有一些阻碍它的东西。可能您已经生成了包含该属性的视图。可能您正在使用提供视图的插件。

【讨论】:

    猜你喜欢
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多