开发者

Display a domain transient property in scaffolded views

开发者 https://www.devze.com 2023-03-06 14:24 出处:网络
In my Grails 1.3.7 project I have a domain class like this: class User { String login String password String name

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.

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 possibl开发者_高级运维e?

Thanks


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:

Install the view templates:

grails InstallTemplates

Then open the relevant templates in src/templates/scaffolding

and modify the line that reads:

persistentPropNames = domainClass.persistentProperties*.name

to

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号