在支架视图中显示域瞬态属性 [英] Display a domain transient property in scaffolded views

查看:80
本文介绍了在支架视图中显示域瞬态属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Grails 1.3.7项目中,我有一个像这样的域类:

In my Grails 1.3.7 project I have a domain class like this:

class User {

String login
String password
String name
String passwordConfirmation

static constraints = {
    login       unique:true, blank:false, maxSize:45
    password    password:true, blank:false, size:8..45, 
                matches: /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*/
    name        blank:false, maxSize:45
    passwordConfirmation display:true, password:true, validator: { val, obj ->
        if (!obj.properties['password'].equals(val)) {
            return ['password.mismatch']
        }}
}

static transients = ['passwordConfirmation']

String toString() {
    name
}

}

我正在使用支架进行相应的创建/编辑操作.

And I'm using scaffold for the corresponding create/edit actions.

我的问题是,即使我将passwordConfirmation约束标记为要显示,它也不会在支架视图中显示.我缺少使瞬时属性显示的某些东西吗?有可能吗?

My problem is that even if I marked passwordConfirmation constraint to be displayed, it isn't shown at the scaffold views. Is there something that I'm missing to make transient properties to be displayed? Is it possible?

谢谢

推荐答案

默认情况下,grails不会在视图中为临时属性创建字段.您可以在每个视图上手动添加它们,或者如果它们很多并且正在使用支架视图,则可以执行以下操作:

By default grails doesn't create the fields in views for transient properties. You could manually add them on each view or if you have a lot of them and are using the scaffolded views you could do the following:

安装视图模板:

grails InstallTemplates

然后在src/templates/scaffolding中打开相关模板

Then open the relevant templates in src/templates/scaffolding

并修改以下内容:

persistentPropNames = domainClass.persistentProperties*.name

persistentPropNames = domainClass.properties*.name

每个模板的

.这有点困难,但是应该可以使用,您可以进一步编辑模板以包括/排除所需的任何属性.

for each of the templates. This is a bit of a bodge, but it should work and you can further edit the template to include/exclude any properties you like.

这篇关于在支架视图中显示域瞬态属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆