本文介绍了如何从Grails脚手架视图隐藏密码字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 根据文档,Grails提供了一个数字对持续性没有影响,但可以自定义脚手架的限制条件。其中之一是密码约束。以下是我使用它的方式: class User { 字符串用户名字符串密码 静态限制= {用户名空白:false 密码空白:false,密码:true } } 与脚手架结合使用时,这会影响编辑视图为我的密码字段使用专用密码输入(这很好),但索引并显示视图仍然以纯文本显示密码(根本不好)。有没有办法在创建和编辑视图中使用密码字段 ,或者至少在其他视图上使用星号或其他字符遮盖密码字段?否则我想知道这个约束的真正好处是什么。我试着指定 display:false,editable:true 作为附加约束,但无济于事。 解决此问题的一种方法是使用定制字段渲染通过字段插件: 创建一个文件夹 grails-app \views\在这个文件夹中放置两个文件: _displayWidget.gsp 和 输入< g:each in =$ {0..value.length( )}>& bull;< / g:each> 放入这两个文件中 密码字段不会从索引和显示视图中消失,但至少您不会再看到它的值,而是一个子弹点的掩码。创建和编辑视图仍然根据属性约束使用密码输入控件。 According to the docs, Grails provides a number of constraints that "have no impact on persistence but customize the scaffolding". One of them is the passwordconstraint. Here's how I use it:class User { String username String password static constraints = { username blank: false password blank: false, password: true }}In combination with scaffolding, this has the effect that the edit view uses a specialized password input for my password field (that's fine), but the index and show view still show the password in plain text (not fine at all). Is there a way to have the password field only in the create and edit views, or at least masked with an asterisk or other character on the other views? Otherwise I wonder what the real benefit of this constraint might be. I tried specifying display: false, editable: true as additional constraints, but to no avail. 解决方案 One way to solve this is by using customized field rendering via the fields plugin:Create a folder grails-app\views\_fields\user\passwordPut two files in this folder: _displayWidget.gsp and _displayWrapper.gspEnter <g:each in="${0..value.length()}">&bull;</g:each> into both filesThe password field will not vanish from index and show views, but at least you won't see it's value any longer, but a mask of bullet points instead. Create and edit view still use the password input widget according to the property constraint. 这篇关于如何从Grails脚手架视图隐藏密码字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-14 19:31