Grails 从域验证器获取会话变量
我确信这是一个常见的情况,但我还没有找到任何答案。我有一个会话范围的变量,用于保存当前登录的用户,我需要通过域对象中的自定义验证器来执行条件验证。有没有办法在验证器中从会话范围中获取当前用户,或者是否有其他方法可以做到这一点,请记住我希望能够从验证器返回特定字段的错误(例如if(isBlank(it))return ['blank','summary',Presentation];
)
基本结构:
class MyDomain
{
String aProperty;
static constraints =
{
aProperty(validator:{
if(isAdmin())return true;
if(isBlank(it))return ['blank','summary',Presentation];
})
}
}
Im sure this is a common scenario, but I haven't found any answers. I have a session-scoped variable that holds the currently signed in user and I need to perform conditional validation by way of a custom validator in a domain object. Is there a way to get the the current user from the session scope while in a validator, or is there perhaps another way to do this, keeping in mind that I want to be able to return the errors for specific fields from my validator(e.g. if(isBlank(it))return ['blank','summary',Presentation];
)
basic struture:
class MyDomain
{
String aProperty;
static constraints =
{
aProperty(validator:{
if(isAdmin())return true;
if(isBlank(it))return ['blank','summary',Presentation];
})
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅这篇文章: http://www.mosbase.com /2011/07/grails-accessing-http-session-from.html
See this post: http://www.mosbase.com/2011/07/grails-accessing-http-session-from.html