在脚手架视图中显示域瞬态属性
在我的 Grails 1.3.7 项目中,我有一个如下所示的域类:
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
}
}
我正在使用脚手架进行相应的创建/编辑操作。
我的问题是,即使我标记了要显示的密码确认约束,它也不会显示在脚手架视图中。我是否缺少某些东西来显示瞬态属性?是否可以?
谢谢
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 possible?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,grails 不会在视图中为瞬态属性创建字段。您可以在每个视图上手动添加它们,或者如果您有很多视图并且正在使用脚手架视图,您可以执行以下操作:
安装视图模板:
然后在 src/templates/scaffolding 中打开相关模板
并修改读取的行:
对于
每个模板。这有点麻烦,但它应该可以工作,您可以进一步编辑模板以包含/排除您喜欢的任何属性。
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:
Then open the relevant templates in src/templates/scaffolding
and modify the line that reads:
to
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.