1

我确定这是一个常见的情况,但我还没有找到任何答案。我有一个包含当前登录用户的会话范围变量,我需要通过域对象中的自定义验证器执行条件验证。有没有办法在验证器中从会话范围获取当前用户,或者是否有另一种方法可以做到这一点,请记住我希望能够从验证器返回特定字段的错误(例如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];
        })
    }
}
4

1 回答 1

3

看到这篇文章:http ://www.mosbase.com/2011/07/grails-accessing-http-session-from.html

于 2011-07-25T15:23:36.580 回答